package com.handinfo.game;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.Actor;
import com.handinfo.engine.Animation;
import com.handinfo.engine.Background;
import com.handinfo.engine.GameManager;
import com.handinfo.engine.resource.ObjectAdapter;
import com.handinfo.engine.resource.ResHead;
import com.handinfo.engine.resource.Resource;
import com.handinfo.engine.resource.ResourceManager;
import com.handinfo.engine.resource.Serializeable;
import com.handinfo.engine.resource.SerializeableImage;
import com.handinfo.uimenu.UIDialogMenu;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.uimenu.window.UIBag;
import com.handinfo.uimenu.window.UIChat;
import com.handinfo.uimenu.window.UIChatInsert;
import com.handinfo.uimenu.window.UIMain;
import com.handinfo.uimenu.window.UIMenu;
import com.handinfo.util.ArrayList;
import com.handinfo.util.BinHeapAStar;
import com.handinfo.util.Tools;

public class ActorRole extends AbstractGameActor
{

	public ActorRole()
	{
		super();
		m_type = AbstractGameActor.ACTOR_TYPE_ROLE;

		m_collideBox[0] = -7;
		m_collideBox[1] = -7;
		m_collideBox[2] = 8;
		m_collideBox[3] = 8;
		m_activeBox[0] = -15;
		m_activeBox[1] = -60;
		m_activeBox[2] = 16;
		m_activeBox[3] = 8;

		initItemCdType();
	}

	public ActorRole(Resource resource)
	{
		super(resource);
		m_type = AbstractGameActor.ACTOR_TYPE_ROLE;

		m_collideBox[0] = -7;
		m_collideBox[1] = -7;
		m_collideBox[2] = 8;
		m_collideBox[3] = 8;
		m_activeBox[0] = -15;
		m_activeBox[1] = -60;
		m_activeBox[2] = 16;
		m_activeBox[3] = 8;

		initItemCdType();
	}

	// ////////////////////////////////////////////
	// 玩家基本属性
	// ////////////////////////////////////////////

	public byte m_sex = 0;// 该角色的性别
	public byte[] m_vocation = null;// 该角色的职业ID
	public byte m_race = 0; // 该角色的种族
	public int m_exp = 0;// 当前经验
	public int m_max_exp = 0;// 当前总经验
	public byte m_mode = 0;// 当前mode
	public byte m_viewpriority = 2;// 显示优先级默认是显示
	public String m_clothhead = "";// 角色的时装头 格式为 性别_种族
	public int m_jinglizhi_zonggong = 0; // 玩家总精力值z
	public int m_jinglizhi_shengyu = 0; // 玩家当前所剩精力值

	public static final String[] ROLE_SEX_LIST = { "无", "男", "女" };
	public static final String[] ROLE_RACE_LIST = { "无", "仙", "妖", "人", "鬼" };
	public static final String[] ROLE_VOCATION_LIST = { "不限制", "剑客", "武者", "道士", "剑侠", "剑豪", "猛将", "斗士", "方士", "术士",
			"剑神", "剑魔", "剑圣", "战狂", "天将", "武圣", "阎罗", "天师", "道圣" };
	public static final String[] FAMILY_POSITION_LIST = { "无", "成员", "长老", "族长" };

	// 职业定义
	public static final int VOCATION_NONE = 127;
	public static final int VOCATION_ALL = 0;
	public static final int VOCATION_JIAN_KE = 1;
	public static final int VOCATION_WU_ZHE = 2;// ...
	public static final int VOCATION_DAO_SHI = 3;
	public static final int VOCATION_JIAN_XIA = 4;
	public static final int VOCATION_JIAN_HAO = 5;
	public static final int VOCATION_MENG_JIANG = 6;// ...
	public static final int VOCATION_DOU_SHI = 7;// ...
	public static final int VOCATION_FANG_SHI = 8;
	public static final int VOCATION_SHU_SHI = 9;
	public static final int VOCATION_JIAN_SHEN = 10;
	public static final int VOCATION_JIAN_MO = 11;
	public static final int VOCATION_JIAN_SHENG = 12;
	public static final int VOCATION_ZHAN_KUANG = 13;// ...
	public static final int VOCATION_TIAN_JIANG = 14;// ...
	public static final int VOCATION_WU_SHENG = 15;// ...
	public static final int VOCATION_YAN_LUO = 16;
	public static final int VOCATION_TIAN_SHI = 17;
	public static final int VOCATION_DAO_SHENG = 18;

	public byte m_captain = 0;// 该玩家是否为队长 0为不是队长 1为是队长

	public String m_family_name = null;// 家族名
	public byte m_position = 0;// 职位 0无 1成员,2长老,3族长
	public long m_contribution = 0;// 家族的贡献

	public Vector m_roleTeam = new Vector();// 队伍信息
	public long m_leaderID = -1;
	public long m_teamID = 0;
	public int m_grade = 0; // 角色等级
	public int m_teamMemberNum = 0;// 队伍里的人数
	public String m_location = null;// 所在位置
	public static final int TEAMMATE_MAX = 4;

	public boolean m_isCasting; // 当前是否在施放战斗技能
	public boolean m_online = false;// 是否在线
	public boolean m_delete = false;// 是否被删除,处在保留期
	public int m_keep_day = 0;// 保留期天数

	// 技能自动寻路
	public boolean m_auto_pathfinding = false;// 是否开启施法自动寻路
	public short m_auto_index = 0;// 寻路的当前索引
	public short[] m_auto_paths = null;// 寻路的路径
	public RoleCombatSkill m_auto_skill = null;// 寻路后施放的技能
	public AbstractGameActor m_auto_target = null;// 寻路后施放的目标

	public boolean m_bScore_show = false;// 战场得分显示
	public byte[] m_faction_key = null;// 阵营key
	public int[] m_faction_score = null;// 阵营得分
	public int m_battlefield_score = 0;// 战场得分
	public byte m_battlefield_flag = 0;// 战场旗子
	public short BATTLEFIELD_FLAG = 95;// 旗子图标索引

	// 寻路
	public ArrayList m_pathfinding_point = null;// 寻路终点集合
	public int m_pathfinding_label = 0;// 寻路终点索引
	public boolean m_pathfinding_pause = false;// 是否暂停
	public boolean m_pathfinding_start = false;// 是否在寻路
	public short[] m_pathfinding_paths = null;// 寻路的路径集合
	public int m_pathfinding_index = 0;
	public long m_pathfinding_id = 0;// 寻路的目标ID
	// 跟随
	public ArrayList m_followTarget_point = null;// 跟随终点集合
	public boolean m_followTarget = false; // 是否开始跟随
	public short[] m_followTarget_paths = null;// 跟随的路径集合
	public int m_followTarget_index = 0;
	public long m_followTarget_id = 0;// 跟随的目标ID
	public boolean m_follow_isArriveTarget = false;
	// 副本
	public ArrayList m_game_carbon = new ArrayList();

	public byte m_vip_lv = 0;// vip等级
	public String m_appellation = null;// 角色称号
	public byte m_appellation_color = 0;// 颜色值
	public final int[] APPELLATION_COLOR = { 0x222222, 0xFFFFFF, 0x00AAFF, 0x00FF55, 0xFFDD00, 0xDD00FF, 0xFF6644,
			0xFF2277 };// 颜色值
	public final int FAMILY_NAME_COLOR = 0x7777FF;// 家族名字颜色

	// ////////////////////////////////////////////////
	// 宏
	// ////////////////////////////////////////////////
	/** 宏总数量 */
	public static final int AMOUNT_MACRO = 4;
	// 宏状态
	/** 准备 */
	public static final int MACRO_STATE_READY = 0;
	/** 进行中 */
	public static final int MACRO_STATE_GOING = 1;
	/** 完成的 */
	public static final int MACRO_STATE_FINISH = 2;
	/** 异常 */
	public static final int MACRO_STATE_EXCEPTION = 3;
	/** 中断 */
	public static final int MACRO_STATE_INTERUPT = 4;

	public GameMacro[] m_game_macro = null;

	// /////////////////////////////////////////////
	// 玩家战斗属性
	// /////////////////////////////////////////////

	// /////////////////////////////////
	// 主角状态
	// /////////////////////////////////

	public void initActor()
	{
		m_bag_equipment = new ActorItem[NUM_BAG_EQUIPMENT];
		m_bag_goods = new ActorItem[NUM_BAG_GOODS];
		//
		m_list_chats = new Vector();
		m_pickItem_IDs = new Vector();
	}

	/**
	 * 宏
	 */

	public void initMarcos(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("初始化宏");
		int num = dis.readByte();
		GameMacro[] gameMacros = new GameMacro[num];
		for (int i = 0; i < num; i++) {
			int itemNum = dis.readByte();
			gameMacros[i] = new GameMacro();
			gameMacros[i].initActionId(itemNum);
			long[][] actionIds = gameMacros[i].m_actionId;
			for (int j = 0; j < itemNum; j++) {
				int type = dis.readByte();
				actionIds[j][GameMacro.MACRO_INDEX_TYPE] = type;// 类型
				if (type != 0) {
					long id = dis.readLong();
					actionIds[j][GameMacro.MACRO_INDEX_ID] = id;
				}
			}
			gameMacros[i].m_actionId = actionIds;
		}
		m_game_macro = new GameMacro[gameMacros.length];
		for (int i = 0; i < gameMacros.length; i++) {
			m_game_macro[i] = gameMacros[i];
			if (m_game_macro[i] == null) {
				Tools.debugPrintln("GameManager.getInstance().m_game_macro[" + i + "] is null");
			}
		}
	}

	/******* 数目限制 ********/
	public static final int NUM_MIN_NAME = 2;// 玩家名字最小字符数目
	public static final int NUM_MAX_NAME = 6;// 玩家名字最大字符数目
	public static final int NUM_MAX_MAIL_TITLE = 8;// 邮件标题最大字符数目
	public static final int NUM_MAX_MAIL_CONTENT = 50;// 邮件内容最大字符数目
	public static final int NUM_MAX_CHAT = 30;// 聊天频道掺入内容最大数目，插入的时候需要判断当前数目

	/******* 金钱 ********/
	public long m_money_game = 0;
	public long m_money_rmb = 0;
	public long m_money_yinpiao = 0;// 银票
	public long m_money_zhangong = 0;// 战功
	public long m_money_banggong = 0;// 帮贡

	/**
	 * 金币
	 */
	public static final byte GOLD = 0;
	/**
	 * 银票
	 */
	public static final byte YINPIAO = 1;
	/**
	 * 元宝
	 */
	public static final byte YUANBAO = 2;
	/**
	 * 战功
	 */
	public static final byte ZHANGONG = 3;
	
	/**
	 * 帮贡
	 * */
	public static final byte BANGGONG = 4;

	public static short[] getMoney(long money)
	{
		short[] num = new short[3];
		num[2] = getMoneyGameCopper(money);
		num[1] = getMoneyGameSilver(money);
		num[0] = getMoneyGameGold(money);
		return num;
	}

	/**
	 * 数值与金币的映射规则
	 * 
	 * @param money
	 * @return
	 */
	public static final short getMoneyGameGold(long money)
	{
		return (short) (money / 10000);
	}

	/**
	 * 数值与银币的映射规则
	 * 
	 * @param money
	 * @return
	 */
	public static final short getMoneyGameSilver(long money)
	{
		return (short) ((money % 10000) / 100);
	}

	/**
	 * 数值与铜币的映射规则
	 * 
	 * @param money
	 * @return
	 */
	public static final short getMoneyGameCopper(long money)
	{
		return (short) (money % 100);
	}

	/**
	 * 金银铜转为数值的映射
	 * 
	 * @param money
	 * @return
	 */
	public static long getMoney(short[] money)
	{
		long temp = 0;
		temp += money[0] * 10000;
		temp += money[1] * 100;
		temp += money[2];
		return temp;
	}

	public boolean m_isNeedFix;// 是否需要修理

	// zeng : 道具信息
	public static final int NUM_BAG_EQUIPMENT = 12;// 装备栏数目
	public static final int NUM_BAG_GOODS = 108;// 物品数目
	public static int s_num_open = 18;// 当前开启的格子数
	//
	public ActorItem[] m_bag_equipment;// 装备栏背包
	public ActorItem[] m_bag_goods;// 橘色背包
	public Hashtable m_items = new Hashtable();// 所有道具集合

	private int NUM_ITEM_CD_TYPE = 10;// 系统中道具使用Cd类型的数目
	public boolean[] m_cd_switch;
	public int[] m_item_type_cd;
	public long[] m_item_time_cd;
	public long[] m_item_time_start;
	public long[] m_item_time_cd_use;

	private void initItemCdType()
	{
		m_cd_switch = new boolean[NUM_ITEM_CD_TYPE];// 是否开启cd
		m_item_type_cd = new int[NUM_ITEM_CD_TYPE];// 道具cd类型
		m_item_time_cd = new long[NUM_ITEM_CD_TYPE];// 道具的Cd时间
		m_item_time_start = new long[NUM_ITEM_CD_TYPE];// 起始时间
		m_item_time_cd_use = new long[NUM_ITEM_CD_TYPE];// 自起始开始过去的cd时间
		// 初始化道具cd类型
		for (int i = 0; i < NUM_ITEM_CD_TYPE; i++) {
			m_item_type_cd[i] = i;
		}
	}

	/**
	 * 开启某类型道具的使用Cd。 当使用某消耗性道具时，启动该方法。 在启动该方法之前需要判断该道具的是否正在CD中。 2012-4-5
	 * 上午09:48:28 venizeng
	 * 
	 * @param type_cd
	 */
	public void startCdTimer(int type_cd, long time_cd)
	{
		int index = getIndexByCdType(type_cd);
		m_cd_switch[index] = true;// 开启
		m_item_time_cd[index] = time_cd;// 设置cd时间
		m_item_time_start[index] = System.currentTimeMillis();// 获得当前时间
	}

	/**
	 * 判断消耗性道具是否在cd状态
	 * 
	 * 2012-4-5 上午10:32:02 venizeng
	 * 
	 * @param consume
	 * @return
	 */
	public boolean isCding(int type_cd)
	{
		if (m_cd_switch == null) {
			return false;
		}
		int index = getIndexByCdType(type_cd);
		if (index < 0 || index >= m_cd_switch.length) {
			return false;
		}
		return m_cd_switch[index];
	}

	/**
	 * 关闭某类型道具的使用Cd 当某道具cd使用完毕会调用此方法 2012-4-5 上午09:48:13 venizeng
	 * 
	 * @param type_cd
	 */
	public void stopCdTimer(int type_cd)
	{
		int index = getIndexByCdType(type_cd);
		m_cd_switch[index] = false;
	}

	/**
	 * 获得当前道具的cd时间 -1：代表未开始 2012-4-5 上午09:53:39 venizeng
	 * 
	 * @param type_cd
	 * @return
	 */
	public long getCdTime(int type_cd)
	{
		if (!isCding(type_cd)) {
			return -1;
		}
		return m_item_time_cd_use[getIndexByCdType(type_cd)];
	}

	/**
	 * 根据Cd类型获得索引 2012-4-5 上午09:47:54 venizeng
	 * 
	 * @param type_cd
	 * @return
	 */
	private int getIndexByCdType(int type_cd)
	{
		return type_cd;
	}

	/**
	 * 运行 2012-4-5 上午09:43:01 venizeng
	 */
	private void logicOnItemCd()
	{
		for (int i = 0; i < NUM_ITEM_CD_TYPE; i++) {
			if (!m_cd_switch[i]) {
				continue;
			}
			m_item_time_cd_use[i] = (System.currentTimeMillis() - m_item_time_start[i]) / 1000;
			if (m_item_time_cd_use[i] >= m_item_time_cd[i]) {
				stopCdTimer(m_item_type_cd[i]);
			}
		}
	}

	/**
	 * 修改当前Items的信息 2012-2-24 下午04:01:34
	 * 
	 * @param ai
	 * @param num
	 */
	public void gameItemNumChanged(ActorItem ai, int num)
	{
		if (ai == null)
			return;
		GameItem item = (GameItem) m_items.get(ai.m_key);
		if (item != null) {
			item.numChanged(num);
		}
		else {
			item = new GameItem();
			item.init(ai);
			m_items.put(item.m_key, item);
		}

		// Enumeration enumeration = m_items.elements();
		// int index = 0;
		// while (enumeration.hasMoreElements()) {
		// GameItem gameItem = (GameItem) enumeration.nextElement();
		// // System.out.println("GameItem[" + index + "].m_name = " +
		// gameItem.m_name + ",Num=" + gameItem.m_num);
		// index++;
		// }
	}

	/**
	 * 通过道具Key获得Item 2012-2-24 下午04:02:31
	 * 
	 * @param key
	 * @return
	 */
	public GameItem getGameItem(String key)
	{
		return (GameItem) m_items.get(key);
	}

	/**
	 * 道具有增加 2012-2-24 下午06:59:04 venizeng
	 * 
	 * @param item
	 */
	private void addActorItemToItems(ActorItem item)
	{
		gameItemNumChanged(item, item.m_num);
	}

	/**
	 * 道具有删除 2012-2-24 下午07:01:26 venizeng
	 * 
	 * @param item
	 */
	public void removeActorItemFromItems(ActorItem item)
	{
		gameItemNumChanged(item, -item.m_num);
	}

	/**
	 * 将道具放置到背包中 2012-3-5 下午04:49:20 venizeng
	 * 
	 * @param item
	 */
	public void addActorItemToBag(ActorItem item)
	{
		if (item == null) {
			return;
		}
		ActorItem[] items = getActorItems(item.m_layer_actorItem);
		if (items != null && items[item.m_index] != null) {
			removeActorItemFromBag(items[item.m_index]);
		}
		addActorItemToItems(item);
		m_bag_goods[item.m_index] = item;
	}

	/**
	 * 将Item从背包里移除 2012-3-1 下午03:23:55 venizeng
	 * 
	 * @param item
	 */
	public void removeActorItemFromBag(ActorItem item)
	{
		if (item == null) {
			return;
		}
		if (m_items.get(item.m_key) != null) {
			removeActorItemFromItems(item);
		}
		m_bag_goods[item.m_index] = null;
	}

	/**
	 * 
	 * 2012-3-5 下午05:36:54 venizeng
	 * 
	 * @param item
	 * @param destNum
	 * 最终Item的数目
	 */
	public void changeActorItemNumFromRole(ActorItem item, int destNum)
	{
		if (item == null) {
			return;
		}
		if (item.m_layer_actorItem == ActorItem.TYPE_BAG_ROLE) {// 只能是背包道具才发生修改
			if (destNum == 0) {// 最终数目为0 ，从背包中移除，并Items中移除
				removeActorItemFromBag(item);
			}
			else {
				gameItemNumChanged(item, destNum - item.m_num);
			}
		}
		else if (item.m_layer_actorItem == ActorItem.TYPE_BAG_EQUIP) {
			if (destNum == 0) {// 最终数目为0 ，从背包中移除，并Items中移除
				removeActorItemFromRole(item);
			}
		}
		item.m_num = destNum;
	}

	/**
	 * 
	 * 2012-3-5 下午05:36:54 venizeng
	 * 
	 * @param item
	 * @param destNum
	 * 最终Item的数目
	 */
	public void exchangeActorItem(byte layer_src, byte layer_dest, int index_src, int index_dest)
	{
		ActorItem[] items_src = getActorItems(layer_src);
		ActorItem src = items_src[index_src];
		ActorItem[] items_dest = getActorItems(layer_dest);
		ActorItem dest = items_dest[index_dest];
		if (src == null) {// 将target直接赋给Src
			if (dest != null) {
				removeActorItemFromRole(dest);
				dest.m_layer_actorItem = layer_src;
				dest.m_index = index_src;
				addActorItemToRole(dest);
			}
		}
		else {
			if (dest == null) {
				removeActorItemFromRole(src);
				src.m_layer_actorItem = layer_dest;
				src.m_index = index_dest;
				addActorItemToRole(src);
			}
			else {
				if (src.m_layer_actorItem == dest.m_layer_actorItem) {
					int tempIndex = src.m_index;
					items_src[index_src].m_index = index_dest;
					items_dest[index_dest].m_index = tempIndex;
				}
				else {
					removeActorItemFromRole(src);// 先从当前道具集合中移除
					removeActorItemFromRole(dest);
					int tempIndex = src.m_index;
					byte tempLayer = src.m_layer_actorItem;
					src.m_layer_actorItem = dest.m_layer_actorItem;
					src.m_index = dest.m_index;
					dest.m_layer_actorItem = tempLayer;
					dest.m_index = tempIndex;
					addActorItemToRole(src);// 添加到相应的道具集合中
					addActorItemToRole(dest);
				}
			}
		}
	}

	/**
	 * 将道具放入到玩家身上才调用 加入到背包中需判断当前此道具是否数目为0，不为0才能加入到背包中
	 * 
	 * @param item
	 */
	public void addActorItemToRole(ActorItem item)
	{
		byte layer = item.m_layer_actorItem;
		int index = item.m_index;
		if (item.m_num == 0) {
			item = null;
		}
		switch (layer) {
			case ActorItem.TYPE_BAG_ROLE:// 角色背包
				addActorItemToBag(item);
				break;
			case ActorItem.TYPE_BAG_EQUIP:// 角色装备背包
				this.m_bag_equipment[index] = item;
				break;
			case ActorItem.TYPE_BAG_STORAGE:// 仓库
				break;
			case ActorItem.TYPE_BAG_PET:// 宠物背包
				break;
		}
	}

	/**
	 * 将道具进行删除 2012-2-24 下午07:04:19 venizeng
	 * 
	 * @param item
	 */
	public void removeActorItemFromRole(ActorItem item)
	{
		if (item == null) {
			return;
		}
		switch (item.m_layer_actorItem) {
			case ActorItem.TYPE_BAG_ROLE:// 角色背包
				removeActorItemFromBag(item);
				break;
			case ActorItem.TYPE_BAG_EQUIP:// 角色装备背包
				m_bag_equipment[item.m_index] = null;
				break;
			case ActorItem.TYPE_BAG_STORAGE:// 仓库
				break;
			case ActorItem.TYPE_BAG_PET:// 宠物背包
				break;
		}
	}

	/**
	 * 初始化背包 2012-2-24 下午03:57:29 venizeng
	 */
	public void initBag()
	{
		if (m_bag_equipment == null) {
			m_bag_equipment = new ActorItem[NUM_BAG_EQUIPMENT];
		}
		if (m_bag_goods == null) {
			m_bag_goods = new ActorItem[NUM_BAG_GOODS];
		}
	}

	/**
	 * 获得道具集合相应的备份 有时候不能对玩家的背包进行直接操作，比如交易，邮件
	 * 
	 * @param items
	 * @return
	 */
	public static final ActorItem[] getActorItemCopys(ActorItem[] items)
	{
		if (items == null) {
			return null;
		}
		ActorItem[] result = new ActorItem[items.length];
		for (int i = 0; i < result.length; i++) {
			result[i] = items[i];
		}
		return result;
	}

	/**
	 * 获得相应的背包
	 * 
	 * @param layer
	 * @return
	 */
	public ActorItem[] getActorItems(byte bagType)
	{
		switch (bagType) {
			case ActorItem.TYPE_BAG_ROLE:// 角色背包
				return m_bag_goods;
			case ActorItem.TYPE_BAG_EQUIP:// 角色装备背包
				return m_bag_equipment;
			case ActorItem.TYPE_BAG_STORAGE:// 仓库
				break;
			case ActorItem.TYPE_BAG_PET:// 宠物背包
				break;
		}
		throw new IllegalArgumentException("无此类型 " + bagType);
	}

	/**
	 * 通过道具的KeyId 找到相应的道具
	 * 
	 * @param keyId
	 * 道具Key的hashCode
	 * @return
	 */
	public final ActorItem getActorItemByKey(String key)
	{
		ActorItem[] items = GameManager.getInstance().m_role.getActorItems(ActorItem.TYPE_BAG_ROLE);
		if (items == null) {
			return null;
		}
		for (int i = 0; i < items.length; i++) {
			if (items[i] == null) {
				continue;
			}
			if (items[i].m_key == key) {
				return items[i];
			}
		}
		return null;
	}

	/**
	 * 通过道具的GUID找到道具
	 * 
	 * @param layer
	 * @param id
	 * @return
	 */
	public final ActorItem getActorItemByGuid(byte layer, long guid)
	{
		ActorItem[] items = GameManager.getInstance().m_role.getActorItems(layer);
		if (items == null) {
			return null;
		}
		for (int i = 0; i < items.length; i++) {
			if (items[i] == null) {
				continue;
			}
			if (items[i].m_guid == guid) {
				return items[i];
			}
		}
		return null;
	}

	/**
	 * 过滤道具，放置到技能栏中只能是如下物品 1：消耗性道具 2： 其他,坐骑
	 * 
	 * @param actorItems
	 * @return
	 */
	public ActorItem[] filterActorItemByShortcut(ActorItem[] actorItems)
	{
		if (actorItems == null) {
			return null;
		}
		int num = 0;
		for (int i = 0; i < actorItems.length; i++) {
			if (actorItems[i] == null) {
				continue;
			}
			if (isFitForShortcut(actorItems[i])) {
				num++;
			}
		}
		if (num == 0) {
			return null;
		}
		ActorItem[] results = new ActorItem[num];
		int index = 0;
		for (int i = 0; i < actorItems.length; i++) {
			if (actorItems[i] == null) {
				continue;
			}
			if (actorItems[i].m_type == ActorItem.TYPE_GOODS_CONSUME) {
				results[index] = actorItems[i];
				index++;
			}
		}
		return results;
	}

	private boolean isFitForShortcut(ActorItem item)
	{
		if (item == null) {
			return false;
		}
		if (item.m_type == ActorItem.TYPE_GOODS_CONSUME
				|| (item.m_type == ActorItem.TYPE_GOODS_OTHER && item.m_type_detail == ActorItem.TYPE_OTHER_RIDE)) {
			return true;
		}
		return false;
	}
	
	public int getItemNum(byte type,String key){
		ActorItem[] items = getActorItems(type);
		if (items == null) {
			return 0 ;
		}
		int num =  0 ;
		for (int i = 0; i < items.length; i++) {
			if (items[i] == null) {
				continue ;
			}
			if (items[i].m_key.equals(key)) {
				num++ ;
			}
		}
		return num ;
	}

	/**
	 * 获得精力值信息
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorVim(DataInputStream dis) throws IOException
	{
		GameManager.getInstance().m_role.m_jinglizhi_zonggong = dis.readInt(); // 总精力值
		GameManager.getInstance().m_role.m_jinglizhi_shengyu = dis.readInt(); // 剩余精力值
		Tools.debugPrintln("剩余精力值: " + GameManager.getInstance().m_role.m_jinglizhi_zonggong);
		Tools.debugPrintln("剩余精力值: " + GameManager.getInstance().m_role.m_jinglizhi_shengyu);
	}

	/**
	 * 获得所有道具信息
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemsFormServer(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：获得所有道具数据");
		short state = dis.readShort();
		String info = dis.readUTF();
		switch (state) {
			case 0:
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);// 加入失败提示
				}
				break;
			case 1:
				int num = dis.readInt();
				for (int i = 0; i < num; i++) {
					ActorItem tempItem = ActorItem.recvActorItemFormServer(dis);
					if (tempItem.m_layer_actorItem == ActorItem.TYPE_BAG_ROLE) {// 只有背包内部数据的修改才需要关注
						ActorItem[] items = getActorItems(tempItem.m_layer_actorItem);// 获得道具所在背包
						if (items[tempItem.m_index] != null) {// 如果是强行替换，则需要将原来的道具从角色身上进行移除
							removeActorItemFromRole(tempItem);
						}
					}
					// 装配背包
					addActorItemToRole(tempItem);
				}
				break;
		}
	}

	/**
	 * 道具使用限制 venizeng
	 * 
	 * @param dis
	 */
	public void recvActorItemLitmit(DataInputStream dis)
	{
		try {
			int num_bag = dis.readInt();// 背包数目
			for (int i = 0; i < num_bag; i++) {
				int itemNum = dis.readInt();// 道具数目
				byte layer = dis.readByte();// 所在层
				ActorItem[] items = getActorItems(layer);
				for (int j = 0; j < itemNum; j++) {
					int index = dis.readInt();// 索引
					if (items[index] == null) {
						continue;
					}
					items[index].m_isOperLocked = dis.readByte() == 0;// 0为受限
					items[index].m_num = dis.readShort();
					if (items[index] instanceof ActorItemEquip) {
						ActorItemEquip equip = (ActorItemEquip) items[index];
						equip.m_naijiu = dis.readShort();
						Tools.debugPrintln("接收指令6024 修理刷新信息：物品名称="+equip.m_name+";耐久="+equip.m_naijiu);
					}
				}
			}
		}
		catch (IOException e) {
			Tools.debug(e);
		}
	}

	/**
	 * 使用道具
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemUse(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String info = dis.readUTF();
		byte layer = 0;
		int index = 0;
		int num = 0;
		ActorItem[] items = null;
		ActorItem item = null;
		// 读取
		switch (state) {
			case 0:
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);// 加入失败提示
				}
				break;
			case 1://
			case 2:
			case 3:
				layer = dis.readByte();
				index = dis.readInt();
				num = dis.readInt();
				items = getActorItems(layer);
				if (items == null) {
					return;
				}
				item = items[index];
				if (items[index] == null) {
					return;
				}
				break;
		}
		// 操作
		switch (state) {
			case 1:
				if (num == item.m_num) {
					return;
				}
				changeActorItemNumFromRole(items[index], num);
				//
				if (items[index] != null) {// 当前格子还有此项道具
					if (items[index] instanceof ActorItemConsume) {
						ActorItemConsume consume = (ActorItemConsume) items[index];
						startCdTimer(consume.m_cd_type, consume.m_time_cd);// 开启cd计时
					}
				}
				// 清除快捷栏或者替换道具Id
				if (num == 0) {
					cleanActorItemInShortCut(item);
				}
				break;
			case 2:
				UIChatInsert.gotoServerSpeaker(item.m_guid);
				break;
			case 3:// 强化某道具
				UIBag.gotoStrengenState(item);
				break;
			default:
				break;
		}
	}

	/**
	 * 从快捷栏中删除 2012-3-5 下午05:42:40 venizeng
	 * 
	 * @param item
	 */
	public void cleanActorItemInShortCut(ActorItem item)
	{
		if (m_items == null) {
			return;
		}
		if (!item.isFitforShortcut()) {// 只有满足能设置快捷栏的道具才需要清理快捷栏
			return;
		}
		int num = 0;
		ActorItem[] items = getActorItems(item.m_layer_actorItem);
		if (items == null) {
			return;
		}
		for (int i = 0; i < items.length; i++) {
			if (items[i] == null) {
				continue;
			}
			if (items[i].m_key == item.m_key) {
				num++;
			}
		}
		boolean isChangeShortcut = false;// 是否需要更改快捷栏
		if (num == 0) {// 背包中已经无此类道具
			for (int i = 0; i < m_shortcut.length; i++) {// 可能有多个
				for (int j = 0; j < m_shortcut[i].length; j++) {
					int type = (int) m_shortcut[i][j][0];
					// if (type == ACTION_TYPE_ITEM &&
					// ActorItem.getActorItemKeyId(item) == m_shortcut[i][j][1])
					// {
					if (type == ACTION_TYPE_ITEM && item.m_guid == m_shortcut[i][j][1]) {
						m_shortcut[i][j][0] = ACTION_TYPE_NONE;
						m_shortcut[i][j][1] = 0;
						isChangeShortcut = true;
					}
				}
			}
		}
		else {// 有同类道具则替换Id
			long id = 0;
			// 查找同key的Id
			for (int i = 0; i < m_bag_goods.length; i++) {
				if (m_bag_goods[i] == null) {
					continue;
				}
				if (m_bag_goods[i].m_key == item.m_key) {
					id = m_bag_goods[i].m_guid;
				}
			}
			// 替换，若Id = 0
			if (id == 0) {
				Tools.debugPrintln("数据错误 ----------> key = " + item.m_key);
			}
			for (int i = 0; i < m_shortcut.length; i++) {// 可能有多个
				for (int j = 0; j < m_shortcut[i].length; j++) {
					int type = (int) m_shortcut[i][j][0];
					if (type == ACTION_TYPE_ITEM && item.m_guid == m_shortcut[i][j][1]) {
						m_shortcut[i][j][0] = AbstractGameActor.ACTION_TYPE_ITEM;
						m_shortcut[i][j][1] = id;// 替换
						isChangeShortcut = true;
					}
				}
			}
		}
		if (isChangeShortcut) {
			GameManager.getInstance().m_game_message.sendSetShortCut(m_shortcut);
			UIMain.updateShortcut();
		}
	}

	/**
	 * 销毁道具
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemDestory(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：销毁道具");
		short state = dis.readShort();
		String info = dis.readUTF();
		switch (state) {
			case 0:
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);// 加入失败提示
				}
				break;
			case 1:
				byte layer = dis.readByte();
				int index = dis.readInt();
				int num = dis.readInt();// 剩余数目
				ActorItem[] items = getActorItems(layer);
				if (items == null) {
					return;
				}
				if (items[index] == null) {
					return;
				}
				ActorItem item = items[index];
				// String name = items[index].m_name;
				// int currentNum = items[index].m_num - num;// 需销毁的数目
				changeActorItemNumFromRole(items[index], num);
				// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
				// name + " X" + currentNum + " 移除成功");
				// 清理道具
				if (num == 0) {
					cleanActorItemInShortCut(item);
				}
				// 清理功能
				if (item != null && item == m_ride) {// 下坐骑
					if ( m_isride ) {
					     zqIsUseRide(false, null, (byte) -1);
						 if( GameManager.getInstance().m_role.m_issendride == -1 ){
							 GameManager.getInstance().m_game_message.sendRideClose();
						 }
					}
				}
				if (item.m_num == 0 && item.m_layer_actorItem == ActorItem.TYPE_BAG_EQUIP) {
					byte _type = 1;
					if (item.m_type == ActorItem.TYPE_GOODS_EQUIPMENT) {
						switch (item.m_type_detail) {
							case ActorItem.TYPE_EQUIPMENT_WEAPON_MAG:
							case ActorItem.TYPE_EQUIPMENT_WEAPON_MUL:
							case ActorItem.TYPE_EQUIPMENT_WEAPON_SIN:
								// 赵铮 添加或更换武器动画
								EquipWeapon(item, _type);// 添加或者更新
								break;
							case ActorItem.TYPE_EQUIPMENT_DRESS:
								// 赵铮 添加或更换时装
								EquipDress(item, _type);// 添加或者更新
								break;
						}
					}
				}
				break;
		}
	}

	/**
	 * 拆分道具
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemDisintegrate(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：拆分道具");
		short state = dis.readShort();
		String info = dis.readUTF();
		switch (state) {
			case 0:
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);// 加入失败提示
				}
				break;
			case 1:
				byte layer_src = dis.readByte();// 源层
				int index_src = dis.readInt();// 源道具的索引
				int num = dis.readInt();// 源道具的最终数目
				ActorItem[] items_src = getActorItems(layer_src);
				if (items_src[index_src] == null) {
					return;
				}
				changeActorItemNumFromRole(items_src[index_src], num);
				//
				byte layer_dst = dis.readByte();
				int index_dst = dis.readInt();
				int num_dst = dis.readInt();
				// long newId = dis.readLong() ;//拆分之后新的Id
				ActorItem[] items_dst = getActorItems(layer_dst);
				if (items_dst[index_dst] != null) {
					return;
					// throw new
					// IllegalArgumentException("recvActorItemDisintegrate 不能放置到已有道具的格子里");
				}
				else {
					if (num_dst != 0) {
						items_dst[index_dst] = ActorItem.clone(items_src[index_src]);
						items_dst[index_dst].m_layer_actorItem = layer_dst;
						items_dst[index_dst].m_index = index_dst;
						// items_dst[index_dst].m_id = newId;
						changeActorItemNumFromRole(items_dst[index_dst], num_dst);
					}
				}
				break;
		}

	}

	/**
	 * 移动道具
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemMove(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("接收到服务器数据 ：移动道具");
		short state = dis.readShort();
		String info = dis.readUTF();
		switch (state) {
			case 0:
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);// 加入失败提示
				}
				break;
			case 1:
				byte layer = dis.readByte();
				ActorItem[] items = getActorItems(layer);
				byte type_oper = dis.readByte();
				int index_src = dis.readInt();
				int num_src = dis.readInt();
				int index_dst = dis.readInt();
				int num_dst = dis.readInt();
				switch (type_oper) {
					case 0: {
						exchangeActorItem(layer, layer, index_src, index_dst);
					}
						break;
					default: {
						changeActorItemNumFromRole(items[index_src], num_src);
						changeActorItemNumFromRole(items[index_dst], num_dst);
					}
						break;
				}
				break;
			default:
				throw new IllegalArgumentException("错误的状态码");
		}
	}

	/**
	 * 装备道具
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemEquip(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("接收到服务器数据 ：装备道具");
		short state = dis.readShort();
		String info = dis.readUTF();
		// Tools.debugPrintln("recvActorItemEquip state = " + state);
		switch (state) {
			case 0: {
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);// 加入失败提示
				}
			}
				break;
			case 1:
				byte layer_src = dis.readByte();
				int index_src = dis.readInt();
				byte layer_dst = dis.readByte();
				int index_dst = dis.readInt();

				exchangeActorItem(layer_src, layer_dst, index_src, index_dst);
				ActorItem item = getActorItems(layer_dst)[index_dst];
				if (item == null) {
					return;
				}
				byte _type = 0;
				if (item.m_type == ActorItem.TYPE_GOODS_EQUIPMENT) {
					switch (item.m_type_detail) {
						case ActorItem.TYPE_EQUIPMENT_WEAPON_MAG:
						case ActorItem.TYPE_EQUIPMENT_WEAPON_MUL:
						case ActorItem.TYPE_EQUIPMENT_WEAPON_SIN:
							// 赵铮 添加或更换武器动画
							EquipWeapon(item, _type);// 添加或者更新
							break;
						case ActorItem.TYPE_EQUIPMENT_DRESS:
							// 赵铮 添加或更换时装
							EquipDress(item, _type);// 添加或者更新
							break;
					}
				}
				break;
			default:
				throw new IllegalArgumentException("错误的状态码");
		}
	}

	/**
	 * 装备时装
	 * 
	 * @param type
	 * */
	public void EquipDress(ActorItem item, int type)
	{
		if (item != null) {
			switch (type) {
				case 0:// 装备或者更新
					Animation anim;
					if (item.m_url == null) {
						Tools.debugPrintln("ERROR 装备时装的URL=NULL");
						return;
					}
					String url = null;
					url = ObjectAdapter.DIR_ANIM.concat(m_clothhead.concat(item.m_url)).concat(
							ObjectAdapter.EXTENSION_ANIM);
					if (m_refsResHead == null) {
						Tools.debugPrintln("ERROR 装备时装时角色依赖资源对象NULL");
						return;
					}
					if (!m_refsResHead[1].m_url.equals(url)) {// 如果装备时装不同以前更换
						ResHead head = new ResHead(ObjectAdapter.RESOURCE_TYPE_ANIM, url, 1);
						anim = (Animation) (ResourceManager.getInstance().loadResource(
								GameManager.getInstance().m_resource_scene, head));
						ResHead r = m_refsResHead[1];
						m_refsResHead[1] = head;
						Animation d = m_anims[1];
						if (anim != null && anim.m_loadFinished) {
							m_anim = anim;
							m_anims[1] = anim;
						}
						else {
							m_anim = GameManager.getInstance().m_shadowAnimation;
							m_anims[1] = GameManager.getInstance().m_shadowAnimation;
						}
						if (!d.m_resHead.m_url.equals(GameManager.getInstance().m_shadowAnimation.m_resHead.m_url)) {
							animsDestroy(d, r);
							d = null;
							r = null;
						}
					}
					url = null;
					break;
				case 1:// 卸下时装
					if (m_refsResHead[1] != null) {
						int sex = GameManager.getInstance().m_role.m_sex - 1;
						int vocation = GameManager.getInstance().m_role.m_vocation[0] - 1;
						int race = GameManager.getInstance().m_role.m_race - 1;
						url = ObjectAdapter.DIR_ANIM.concat(GameManager.s_roleModemList[sex][vocation][race]).concat(
								ObjectAdapter.EXTENSION_ANIM);
						ResHead resHead = new ResHead(ObjectAdapter.RESOURCE_TYPE_ANIM, url, 1);
						anim = (Animation) (ResourceManager.getInstance().loadResource(
								GameManager.getInstance().m_resource_scene, resHead));
						ResHead r = m_refsResHead[1];
						Animation d = m_anims[1];
						m_refsResHead[1] = resHead;
						if (anim != null && anim.m_loadFinished) {
							m_anims[1] = anim;
							m_anim = anim;
						}
						else {
							m_anim = GameManager.getInstance().m_shadowAnimation;
							m_anims[1] = GameManager.getInstance().m_shadowAnimation;
						}
						if (!d.m_resHead.m_url.equals(GameManager.getInstance().m_shadowAnimation.m_resHead.m_url)) {
							animsDestroy(d, r);
							d = null;
							r = null;
						}

					}
					break;
			}
		}
	}

	// /** 清理掉更变前的角色列表
	// * @param head 角色对应的动画头
	// * @param anim 角色更改前的动画
	// * @param _anim 角色更改后的动画
	// * */
	// private void cleanRoleList(ResHead head,Animation anim,Animation _anim){
	// if ( head != null ) {
	// GameManager.getInstance().m_roleResList.reMove(head);
	// }
	// if ( anim!= null && anim.m_refsResHead != null
	// && anim.m_refsResHead.length > 0 ) {
	// for (int i = 0; i < anim.m_refsResHead.length; i++) {
	// GameManager.getInstance().m_roleResList.reMove(anim.m_refsResHead[i]);
	// }
	// }
	// if ( _anim!= null && _anim.m_refsResHead != null
	// && _anim.m_refsResHead.length > 0 ) {
	// for (int i = 0; i < _anim.m_refsResHead.length; i++) {
	// GameManager.getInstance().m_roleResList.put(_anim.m_refsResHead[i]);
	// }
	// }
	// }
	/**
	 * 装备武器
	 * 
	 * @param type
	 * */
	public void EquipWeapon(ActorItem item, byte type)
	{
		if (item != null) {
			switch (type) {
				case 0:// 装备或者更新
					Animation anim;
					if (item.m_url == null) {
						Tools.debugPrintln("ERROR 装备武器的URL=NULL");
						return;
					}
					if (m_refsResHead[2] == null) {// 如果当前没有武器的依赖资源
						Tools.debugPrintln("当前为空 道具的URL=" + item.m_url);
						m_refsResHead[2] = new ResHead(ObjectAdapter.RESOURCE_TYPE_ANIM, item.m_url, 1);
						anim = (Animation) (ResourceManager.getInstance().loadResource(
								GameManager.getInstance().m_resource_scene, m_refsResHead[2]));
						if (anim != null && anim.m_loadFinished) {
							m_anims[2] = anim;
						}
						else {
							m_anims[2] = null;
						}
					}
					else {// 当前有依赖资源
						Tools.debugPrintln("当前有武器 需要 更换武器的URL=" + item.m_url);
						if (!m_refsResHead[2].m_url.equals(item.m_url)) {
							ResHead r = m_refsResHead[2];
							Animation d = m_anims[2];
							ResHead head = new ResHead(ObjectAdapter.RESOURCE_TYPE_ANIM, item.m_url, 1);
							m_refsResHead[2] = head;
							anim = (Animation) (ResourceManager.getInstance().loadResource(
									GameManager.getInstance().m_resource_scene, m_refsResHead[2]));
							if (anim != null && anim.m_loadFinished) {
								m_anims[2] = anim;
							}
							else {
								m_anims[2] = null;
							}
							animsDestroy(d, r);
							d = null;
							r = null;
						}
					}
					break;
				case 1:// 卸下武器
					if (m_refsResHead[2] != null) {
						if (m_anims[2] != null) {
							animsDestroy(m_anims[2], m_refsResHead[2]);
						}
						m_refsResHead[2] = null;
						m_anims[2] = null;
					}
					break;
			}
		}
	}

	/**
	 * 卸载道具
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemUninstall(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：卸载道具");
		short state = dis.readShort();
		String info = dis.readUTF();
		switch (state) {
			case 0:
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);// 加入失败提示
				}
				break;
			case 1:
				byte layer_src = dis.readByte();
				int index_src = dis.readInt();
				byte layer_dst = dis.readByte();
				int index_dst = dis.readInt();
				// 修改源Item的层及位置信息
				// ActorItem item_src = getActorItems(layer_src)[index_src];
				// item_src.m_layer_actorItem = layer_dst;
				// item_src.m_index = index_dst;
				// // 将其放置到目标位置

				// if (items_dst[index_dst] != null) {
				// throw new IllegalArgumentException("卸载到的背包格子不为空，不能进行卸载操作");
				// }
				// items_dst[index_dst] = item_src;
				// // 赵铮
				// EquipWeapon(getActorItems(layer_src)[index_src], 1);// 卸下
				// // 将该层中道具清空
				// getActorItems(layer_src)[index_src] = null;

				ActorItem[] items_dst = getActorItems(layer_src);
				ActorItem item = items_dst[index_src];
				exchangeActorItem(layer_src, layer_dst, index_src, index_dst);
				byte _type = 1;
				if (item.m_type == ActorItem.TYPE_GOODS_EQUIPMENT) {
					switch (item.m_type_detail) {
						case ActorItem.TYPE_EQUIPMENT_WEAPON_MAG:
						case ActorItem.TYPE_EQUIPMENT_WEAPON_MUL:
						case ActorItem.TYPE_EQUIPMENT_WEAPON_SIN:
							// 赵铮 添加或更换武器动画
							EquipWeapon(item, _type);// 添加或者更新
							break;
						case ActorItem.TYPE_EQUIPMENT_DRESS:
							// 赵铮 添加或更换时装
							EquipDress(item, _type);// 添加或者更新
							break;
					}
				}
				break;
		}
	}

	/**
	 * 整理道具
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemTrim(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：整理道具");
		GameManager.getInstance().m_role.m_bag_goods = null;
		GameManager.getInstance().m_role.m_bag_goods = new ActorItem[NUM_BAG_GOODS];
		recvActorItemsFormServer(dis);
	}

	/**
	 * 扩容
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemKuorong(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：扩容道具");
		short state = dis.readShort();
		String info = dis.readUTF();
		if (!info.equals("")) {
			GameManager.getInstance().addMessage(info);// 加入失败提示
		}
		switch (state) {
			case 0:
				break;
			case 1:
				byte layer = dis.readByte();
				int num = dis.readInt();
				switch (layer) {
					case ActorItem.TYPE_BAG_ROLE:
//				if (num <= s_num_open) {
//					return;
//				}
						s_num_open = num;// 测试用，需要服务器重新传值
						break;
				}
				break;
		}
	}

	/**
	 * 扩容
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemJiebang(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：扩容道具");
		byte state = dis.readByte();
		String info = dis.readUTF();
		if (!info.equals("")) {
			GameManager.getInstance().addMessage(info);// 加入失败提示
		}
	}

	/**
	 * 2012-5-3 下午01:56:31 venizeng
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemResolve(DataInputStream dis) throws IOException
	{
		byte state = dis.readByte();
		String info = dis.readUTF();
		if (!info.equals("")) {
			GameManager.getInstance().addMessage(info);// 加入失败提示
		}
	}

	/**
	 * 合成信息
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemHeCheng(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：接收到合成信息");
		short state = dis.readShort();
		String info = dis.readUTF();
		if (!info.equals("")) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, info);
		}
		if (state == 0) {
			return;
		}
		int num = dis.readInt();
		for (int i = 0; i < num; i++) {
			int index = dis.readInt();
			int num1 = dis.readInt();
			changeActorItemNumFromRole(m_bag_goods[index], num1);
		}
		// 下述为新宝石信息
		int num_new = dis.readInt();
		for (int i = 0; i < num_new; i++) {
			ActorItem item = ActorItem.recvActorItemFormServer(dis);
			addActorItemToRole(item);
		}
	}

	/**
	 * 镶嵌
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemXiangqian(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：接收到镶嵌信息");
		short state = dis.readShort();
		String info = dis.readUTF();
		if (!info.equals("")) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, info);
		}
		if (state == 0) {
			return;
		}
		GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C, "宝石镶嵌成功，属性获得提升。");
		byte layer = dis.readByte();// 背包层
		ActorItem[] items = getActorItems(layer);
		int index_jewel = dis.readInt();// 宝石索引
		int num_jewel = dis.readInt();// 宝石数目
		changeActorItemNumFromRole(items[index_jewel], num_jewel);

		// 下述为新道具信息
		ActorItem item = ActorItem.recvActorItemFormServer(dis);
		addActorItemToRole(item);
	}

	/**
	 * 提取
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemTiqu(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：接收到提取信息");
		short state = dis.readShort();
		String info = dis.readUTF();
		if (!info.equals("")) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, info);
		}
		if (state == 0) {
			return;
		}
		int num = dis.readInt();
		for (int i = 0; i < num; i++) {
			ActorItem item = ActorItem.recvActorItemFormServer(dis);
			addActorItemToRole(item);
		}
	}

	/**
	 * 骑乘
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemDrive(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：接收到骑乘信息");
		short state = dis.readShort();
		String info = dis.readUTF();
		if (!info.equals("")) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, info);
		}
		if (state == 0) {
			return;
		}
	}

	/**
	 * 初始化时，有多少格子开放
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorItemNumOpen(DataInputStream dis) throws IOException
	{
		// Tools.debugPrintln("接收到服务器数据 ：背包 开启数目");
		short state = dis.readShort();
		String info = dis.readUTF();
		switch (state) {
			case 0:
				if (!info.equals("")) {
					GameManager.getInstance().addMessage(info);//
				}
				break;
			case 1:
				int num = dis.readInt();
				for (int i = 0; i < num; i++) {
					byte layer = dis.readByte();
					int num_open = dis.readInt();
					switch (layer) {
						case ActorItem.TYPE_BAG_ROLE:
							s_num_open = num_open;
							break;
					}
				}
				break;
		}
	}

	// 聊天
	public Vector m_list_chats;

	public static int MAXNUM_CHATLIST = 30;// 最大聊天记录

	// 接收最大聊天记录数目
	public void readChatMaxNum(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String info = dis.readUTF();
		if (state == 0) {
			if (!info.equals("")) {
			}
			return;
		}
		MAXNUM_CHATLIST = dis.readInt();
	}

	// 获得相应类型的聊天记录
	public final ChatItem[] getChatItemFitType(byte type)
	{
		if (m_list_chats == null) {
			m_list_chats = new Vector();
		}
		int size = m_list_chats.size();
		if (size == 0) {
			return null;
		}
		ArrayList list = new ArrayList();
		for (int i = 0; i < size; i++) {
			ChatItem item = (ChatItem) m_list_chats.elementAt(i);
			if ((type == ChatItem.TYPE_QUAN || type == item.m_type)) {
				list.addElement(item);
			}
		}
		size = list.size();
		if (size <= 0) {
			return null;
		}
		ChatItem[] items = new ChatItem[size];
		for (int i = 0; i < size; i++) {
			items[i] = (ChatItem) list.elementAt(i);
		}
		return items;
	}

	/**
	 * 加入到聊天系统
	 * 
	 * @param item
	 */
	public void addToChat(ChatItem item)
	{
		/*
		 * if (item.m_id_sender == GameManager.getInstance().m_role.m_gameID) {
		 * return; }
		 */
		Vector vector = m_list_chats;
		if (vector.size() == ActorRole.MAXNUM_CHATLIST) {
			vector.removeElementAt(0);// 移除第一条
		}
		vector.addElement(item);// 将最后一条加入
		UIMain.updateChat();
		UIChat.updateChat();
	}

	//
	public ArrayList m_drama_list = new ArrayList();// 剧情任务列表
	public ArrayList m_event_list = new ArrayList();// 活动任务列表
	public ArrayList m_acceptably_list = new ArrayList();// 可接任务列表

	private int currTimes = 0;// 自身时间判断
	private final int maxTimes = 30;// 自身运行最大数

	/**
	 * 判断图片内存低于阀值恢复自身原样
	 **/
	private void isRecoveryNormal()
	{
		if (currTimes < maxTimes) {
			currTimes++;
		}
		else {
			if (!SerializeableImage.isFreeMemory()) {
				if (m_refsResHead != null && m_refsResHead.length > 0) {// 只要当前角色有依赖关系
					Animation anim;
					for (int i = 0; i < m_refsResHead.length; i++) {
						if (m_refsResHead[i] != null) {// 如果当前依赖资源不为空
							if ( m_anims[i] == null ) {// 如果当前无动画
								anim = (Animation) ResourceManager.getInstance().loadResource(
										GameManager.getInstance().m_resource_scene, m_refsResHead[i]);
								if (anim != null && anim.m_loadFinished) {// 动画成功
									m_anims[i] = anim;
								}
								else {
									if (i == 1 ) {// 如果是角色资源
										m_anims[i] = GameManager.getInstance().m_shadowAnimation;
									}
								}
							}
							else {
								if (!m_anims[i].m_resHead.equals(m_refsResHead[i])) {// 如果当前动画本身与依赖资源不一样
									anim = (Animation) ResourceManager.getInstance().loadResource(
											GameManager.getInstance().m_resource_scene, m_refsResHead[i]);
									ResHead r = m_anims[i].m_resHead;
									Animation d = m_anims[i];
									if (anim != null && anim.m_loadFinished) {// 动画成功
										m_anims[i] = anim;
										if (!d.m_resHead.m_url.equals(GameManager.getInstance().m_shadowAnimation.m_resHead.m_url)) {
											animsDestroy(d, r);
											d = null;
											r = null;
										}

									}// 创建失败还用原来的
								}
							}
						}
					}
					if (m_anims != null && m_anims[1] != null) {
						m_anim = m_anims[1];
					}
					else {
						Tools.debugPrintln("ActorRole 自己更新时动作出错 role.m_anims[1]=null");
					}
				}
			}
			currTimes = 0;
		}
	}

	public byte m_macro_index = 0;
	public boolean m_macro_open = false;

	public void stopMacro()
	{
		if (m_game_macro != null) {
			GameMacro gm = m_game_macro[m_macro_index];
			gm.reset();
		}
		m_macro_index = 0;
		m_macro_open = false;
	}
	
	public void stopAutoHangUp(){
		if( m_guaji ){
			m_guaji = false;
			keyAnyStopOther();
			Tools.debugPrintln("进停止挂机！");
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "自动打怪功能因被打断关闭！");
		}
	}

	/**
	 * 逻辑
	 */
	public void logic()
	{
		// 循环判断内存
		isRecoveryNormal();
        
		// 只有玩家控制角色才需要做地图层的物理碰撞
		if (this == ((GameScene) m_scene).m_controlledActor) {
			guaji();//zuobi 挂机
			if (!m_auto_pathfinding && !m_pathfinding_start) {
				bgCollide();
			}
			// 技能和物品cooldown
			cooldown();
			// 施法计时
			castingTimeTick();
			// 拾取道具
			pickItem();
			sceneAutoPathfinding();
			scenefollowTarget();
			if (m_followTarget && GameManager.getInstance().m_scene.m_frameCount % 10 == 0) {
				followTargetUpdataPoint();
			}
			if (m_macro_open && m_game_macro != null && m_macro_index >= 0 && m_macro_index < m_game_macro.length) {
				GameMacro gm = m_game_macro[m_macro_index];
				if (gm != null) {
					gm.doAction();
				}
			}
			else {
				autoFight();
			}
			// 技能自动寻路
			if (m_auto_pathfinding) {
				autoPathfindingLogic();
			}
		}
		super.logic();

		// 对目标产生伤害
		if (dealTargetDamage(true)) {
			// 对于瞬发以及吟唱法术，目标伤害数值处理完毕即可认为该施法过程结束
			// m_isCasting = false;
		}

		// combatTimeCountDown();
		switch (m_actionIDNow / DIRECT_NUM) {
			case ACTION_STANDUP:
				if (m_actionOver && !m_actionCycle) {
					// if (GameManager.getInstance().m_role.m_isride) {
					// setAction(GameManager.getInstance().m_role.actionRideStand +
					// m_direct, 0, 0, true, false);
					// }
					// else {
					setAction(ACTION_STAND * DIRECT_NUM + m_direct, 0, 0, true, false);
					// }

				}
				break;
			case ACTION_SITDOWN:
				if (m_actionOver && !m_actionCycle) {
					setAction(ACTION_SIT * DIRECT_NUM + m_direct, 0, 0, true, false);
				}
				break;
			case ACTION_HURT1:
			case ACTION_HURT2:
			case ACTION_HURT3:
			case ACTION_HURT4:
			case ACTION_HURT5:
			case ACTION_HURT6:
				if (m_actionOver && !m_actionCycle) {
					setAction(ACTION_STAND * DIRECT_NUM + m_direct, 0, 0, true, false);
				}
				break;
			case ACTION_DEAD1:
			case ACTION_DEAD2:
			case ACTION_DEAD3:
			case ACTION_DEAD4:
				// if (m_actionOver) {
				// deactivate();
				// }
				break;
			case ACTION_ATTACK1:
			case ACTION_ATTACK2:
			case ACTION_ATTACK3:
			case ACTION_ATTACK4:
			case ACTION_ATTACK5:
			case ACTION_ATTACK6:
			case ACTION_ATTACK7:
			case ACTION_ATTACK8:
			case ACTION_OTHER1:
			case ACTION_CAST1:
			case ACTION_CAST2:
			case ACTION_CAST3:
			case ACTION_CAST4:
			case ACTION_CAST5:
			case ACTION_CAST6:
				if (m_curCombatSkill != null) {
					switch (m_curCombatSkill.m_type) {
						// 吟唱型
						case RoleCombatSkill.TYPE_SING:
							// //吟唱结束，发动施法
							if (m_actionIDNow / DIRECT_NUM == m_curCombatSkill.m_singActionId
									&& m_castingTimeCounter > 0) {
								// m_castingTimeCounter--;
							}
							// 施法结束，立正！
							if (m_actionIDNow / DIRECT_NUM == m_curCombatSkill.m_castSrcActionId && m_actionOver) {
								Tools.debugPrintln("清除施法条!");
								setAction(ACTION_STAND * DIRECT_NUM + m_direct, 0, 0, true, true);
								m_isCasting = false;
								stopCasting();
								stopCastingDescription();
							}
							break;
						// 瞬发型
						case RoleCombatSkill.TYPE_COMMON:
							// 施法结束，立正！
							if (m_actionIDNow / DIRECT_NUM == m_curCombatSkill.m_castSrcActionId && m_actionOver) {
								setAction(ACTION_STAND * DIRECT_NUM + m_direct, 0, 0, true, true);
							}
							break;
						// 通道型
						case RoleCombatSkill.TYPE_CONTINUOUS:
							// 时间结束，立正！
							if (m_actionIDNow / DIRECT_NUM == m_curCombatSkill.m_castSrcActionId
									&& m_castingTimeCounter <= 0) {
								setAction(ACTION_STAND * DIRECT_NUM + m_direct, 0, 0, true, true);
								m_isCasting = false;
								stopCasting();
							}
							break;
					}
				}
				break;
		}
		dealCastEnd();
		// Cd时间逻辑
		logicOnItemCd();
	}

	/**
	 * 角色的按键移动
	 */
	public void keyDir()
	{
		showDeadDialogMenu();
		// if (this == m_scene.m_focusActor &&
		// (!GameManager.s_isControlledByUi)) {
		if (this == m_scene.m_focusActor) {
			if (canMove()) {
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)
						|| AbstractGameScreen.haveKeyHold(AbstractGameScreen.GK_UP)) {
					move(DIRECT_N);
					keyAnyStopOther();
					stopAutoHangUp();
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)
						|| AbstractGameScreen.haveKeyHold(AbstractGameScreen.GK_DOWN)) {
					move(DIRECT_S);
					keyAnyStopOther();
					stopAutoHangUp();
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)
						|| AbstractGameScreen.haveKeyHold(AbstractGameScreen.GK_LEFT)) {
					move(DIRECT_W);
					keyAnyStopOther();
					stopAutoHangUp();
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)
						|| AbstractGameScreen.haveKeyHold(AbstractGameScreen.GK_RIGHT)) {
					move(DIRECT_E);
					keyAnyStopOther();
					stopAutoHangUp();
				}
				else {
					reviseAction();
				}
			}
			else {
				reviseAction();
			}
		}
		// 目标相关
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_B)) {
			((GameScene) m_scene).changeTargetActor(true, false);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_D)) {
			((GameScene) m_scene).changeTargetActor(false, false);
		}
		if (m_targetActor == null) {
			if (((GameScene) m_scene).changeTargetActor(false, true) == null) {
				((GameScene) m_scene).changeTargetActor(true, true);
			}
		}
		else if (!m_targetActor.m_needDraw || !m_targetActor.m_enabled || !m_targetActor.m_visible) {
			((GameScene) m_scene).setTargetActor(null);
		}
	}

	public void keyAnyStopOther()
	{
		clearAutoAttack();
		clearPathfinding();
		clearFollowTarget();
		stopMacro();
	}

	private void reviseAction()
	{
		switch (m_actionIDNow / DIRECT_NUM) {
			case ACTION_MOVE:
				if (!m_auto_pathfinding && !m_pathfinding_start && !m_follow_isArriveTarget)
					stay(m_direct);
				break;
			case ACTION_DEAD1:
			case ACTION_DEAD2:
			case ACTION_DEAD3:
			case ACTION_DEAD4:
				setAction(ACTION_DEAD1 * DIRECT_NUM + m_direct, 0, 0, false, false);
				break;
			case ACTION_RIDEMOVE1:
				if (!m_auto_pathfinding && !m_pathfinding_start && !m_follow_isArriveTarget) {
					setAction(ACTION_RIDESTAND1 * DIRECT_NUM + m_direct, 0, 0, true, false);
				}
				break;
			case ACTION_RIDEMOVE2:
				if (!m_auto_pathfinding && !m_pathfinding_start && !m_follow_isArriveTarget) {
					setAction(ACTION_RIDESTAND2 * DIRECT_NUM + m_direct, 0, 0, true, false);
				}
				break;
			case ACTION_RIDEMOVE3:
				if (!m_auto_pathfinding && !m_pathfinding_start && !m_follow_isArriveTarget) {
					setAction(ACTION_RIDESTAND3 * DIRECT_NUM + m_direct, 0, 0, true, false);
				}
				break;
		}
	}

	// private int m_buffer_x = 0;//移动缓冲x
	// private int m_buffer_y = 0;//移动缓冲y
	// private final int BUFFER_CHANGE_RANGE = 8;
	// /**
	// * 战斗状态倒计时
	// */
	// public void combatTimeCountDown()
	// {
	// if (m_combat_status) {
	// if (m_combat_exit_time <= 0) {
	// m_combat_status = false;
	// GameManager.getInstance().addSystemInfo(
	// GameManager.SYSTEM_INFO_TYPE_A, "离开战斗!");
	// }
	// else {
	// m_combat_exit_time--;
	// }
	// }
	// }

	/**
	 * 角色是否能移动
	 * 
	 * @return
	 */
	public boolean canMove()
	{
		if ((m_action & ACTOR_ACTION_RANDOM_MOVE) != 0 || (m_action & ACTOR_ACTION_FORBIT_MOVE) != 0
				|| (m_action & ACTOR_ACTION_SCRIPT_MOVE) != 0) {
			((GameScene) m_scene).addMessage(SKILL_HINT_GZ, Tools.RED, Tools.BLACK);
			return false;
		}
		if ((m_action & ACTOR_ACTION_FORBIT_ATTACK_SKILL) != 0) {
			((GameScene) m_scene).addMessage(SKILL_HINT_DS, Tools.RED, Tools.BLACK);
			return false;
		}
		boolean result = true;
		int actionID = m_actionIDNow / DIRECT_NUM;
		switch (m_actionIDNow / DIRECT_NUM) {
			case ACTION_ATTACK1:
			case ACTION_ATTACK2:
			case ACTION_ATTACK3:
			case ACTION_ATTACK4:
			case ACTION_ATTACK5:
			case ACTION_ATTACK6:
			case ACTION_ATTACK7:
			case ACTION_ATTACK8:
			case ACTION_OTHER1:
				if (m_curCombatSkill == null)
					return true;
				if (m_curCombatSkill.m_castSrcActionId == actionID
						&& (m_curCombatSkill.m_type == RoleCombatSkill.TYPE_COMMON || m_curCombatSkill.m_type == RoleCombatSkill.TYPE_SING)) {
					result = false;
				}
				break;
			default:
				break;
		}
		if (m_status == ACTOR_STATUS_ROLE_DEAD) {
			result = false;
		}
		return result;
	}

	public void move(int direct, int velocity)
	{
		// Tools.debugPrintln("name="+m_name+";m_isride="+m_isride);
		if (m_isride) {
			switch (direct) {
				case DIRECT_E:
					m_flipX = false;
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, velocity, 0, true,
							false);
					break;
				case DIRECT_S:
					if (m_direct == DIRECT_W) {
						m_flipX = true;
					}
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, 0, velocity, true,
							false);
					break;
				case DIRECT_W:
					m_flipX = false;
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, velocity, 0, true,
							false);
					break;
				case DIRECT_N:
					if (m_direct == DIRECT_W) {
						m_flipX = true;
					}
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, 0, velocity, true,
							false);
					break;
			}
		}
		else {
			super.move(direct, velocity);
		}
		if (m_gameID == GameManager.getInstance().m_role.m_gameID) {
			if (m_isCasting) {
				m_isCasting = false;
				GameManager.getInstance().m_game_message.sendCastCancel();
				stopCasting();
				stopCastingDescription();
			}
			if (((GameScene) m_scene).m_interact_start) {
				((GameScene) m_scene).endNPCInteract();
				stopCasting();
				stopCastingDescription();
			}
			if (m_auto_pathfinding) {
				stay(m_direct);
				resetAutoPathfinding();
			}
		}
	}

	public void move(int direct)
	{
		if (m_isride) {
			switch (direct) {
				case DIRECT_E:
					m_flipX = false;
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, m_velocity, 0, true,
							false);
					break;
				case DIRECT_S:
					if (m_direct == DIRECT_W) {
						m_flipX = true;
					}
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, 0, m_velocity, true,
							false);
					break;
				case DIRECT_W:
					m_flipX = false;
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, -m_velocity, 0, true,
							false);
					break;
				case DIRECT_N:
					if (m_direct == DIRECT_W) {
						m_flipX = true;
					}
					setAction((ACTION_RIDEMOVE1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, 0, -m_velocity, true,
							false);
					break;
			}
		}
		else {
			super.move(direct);
		}
		if (m_gameID == GameManager.getInstance().m_role.m_gameID) {
			if (m_isCasting) {
				m_isCasting = false;
				GameManager.getInstance().m_game_message.sendCastCancel();
				stopCasting();
				stopCastingDescription();
			}
			if (((GameScene) m_scene).m_interact_start) {
				((GameScene) m_scene).endNPCInteract();
				stopCasting();
				stopCastingDescription();
			}
			if (m_auto_pathfinding) {
				stay(m_direct);
				resetAutoPathfinding();
			}
		}
	}

	/**
	 * 站立
	 */
	public void stay(int direct)
	{

		if (m_isride) {
			// Tools.debugPrintln("stay m_ride.m_rideType=" +
			// m_ride.m_rideType);
			setAction((ACTION_RIDESTAND1 + m_ride.m_rideType - 1) * DIRECT_NUM + direct, 0, 0, true, false);
		}
		else {
			setAction(ACTION_STAND * DIRECT_NUM + direct, 0, 0, true, false);
		}
	}

	public void startCasting(int time)
	{
		m_castingTimeCounter = time;
		m_castingTime = time;
		// 保证在开始绘制前已经赋值
		// UiManager.getInstance().castingChanged(true);
		UIMain.updataCasting(true);
	}

	public void stopCasting()
	{
		// 保证在关闭绘制后再清零
		// UiManager.getInstance().castingChanged(false);
		UIMain.updataCasting(false);
		m_castingTime = 0;
		m_castingTimeCounter = 0;
	}

	public void startCastingDescription(String content)
	{
		// 保证在关闭绘制后再清零
		// UiManager.getInstance().castingDescpChanged(true, content);

		UIMain.updataCastingDescp(true, content);
	}

	public void stopCastingDescription()
	{
		// 保证在关闭绘制后再清零
		// UiManager.getInstance().castingDescpChanged(false, null);
		UIMain.updataCastingDescp(false, null);
	}

	/**
	 * 角色当前动作是否可以被技能打断
	 * 
	 * @return
	 */
	public boolean canBeInterrupt(boolean force)
	{
		int actionID = m_actionIDNow / DIRECT_NUM;
		switch (actionID) {
			case ACTION_STAND:
			case ACTION_MOVE:
				return true;
			case ACTION_ATTACK1:
			case ACTION_ATTACK2:
			case ACTION_ATTACK3:
			case ACTION_ATTACK4:
			case ACTION_ATTACK5:
			case ACTION_ATTACK6:
			case ACTION_ATTACK7:
			case ACTION_ATTACK8:
			case ACTION_OTHER1:
			case ACTION_CAST1:
			case ACTION_CAST2:
			case ACTION_CAST3:
			case ACTION_CAST4:
			case ACTION_CAST5:
			case ACTION_CAST6:
				if (m_curCombatSkill == null)
					return true;
				// 瞬发法术以及吟唱法术的施法阶段无法打断
				if (m_curCombatSkill.m_castSrcActionId == actionID
						&& (m_curCombatSkill.m_type == CombatSkill.TYPE_COMMON || m_curCombatSkill.m_type == CombatSkill.TYPE_SING)) {
					return false;
				}
				// 通道法术，如果不是强制打断，则不会打断
				else if (m_curCombatSkill.m_castSrcActionId == actionID
						&& m_curCombatSkill.m_type == CombatSkill.TYPE_CONTINUOUS && !force) {
					return false;
				}
				// 吟唱法术的吟唱阶段，如果不是强制打断，则不会打断
				else if (m_curCombatSkill.m_singActionId == actionID
						&& m_curCombatSkill.m_type == CombatSkill.TYPE_SING && !force) {
					return false;
				}
				else {
					return true;
				}
			default:
				return false;
		}
	}

	public void dealCastEnd()
	{
		if (m_curCombatSkill != null && !m_isCasting
				&& m_actionIDNow / DIRECT_NUM != m_curCombatSkill.m_castSrcActionId
				&& m_actionIDNow / DIRECT_NUM != m_curCombatSkill.m_singActionId) {
			m_curCombatSkill = null;
			// initAutoAttack();
		}
	}

	public void setAction(int actionIDNext, boolean mustChange)
	{
		// 用于吟唱以及通道的持续光效
		if (m_castSrcEffect != null && m_actionIDNow / DIRECT_NUM != actionIDNext / DIRECT_NUM) {
			((GameScene) m_scene).removeEffect(m_castSrcEffect);
			m_castSrcEffect = null;
		}
		super.setAction(actionIDNext, mustChange);
	}

	/**
	 * 更新移动信息（根据服务器传回的数据来移动）
	 */
	public void updateMove()
	{
		switch (m_actionIDNow / DIRECT_NUM) {
			default:
				return;
			case ACTION_STAND:
			case ACTION_MOVE:
			case ACTION_RIDEMOVE1:
			case ACTION_RIDEMOVE2:
			case ACTION_RIDEMOVE3:
			case ACTION_RIDESTAND1:
			case ACTION_RIDESTAND2:
			case ACTION_RIDESTAND3:
				break;
		}
		if (this != GameManager.getInstance().m_role)
			super.updateMove();
	}

	/**
	 * 更新位置信息
	 */
	public void updatePos()
	{
		super.updatePos();
		if (m_scene == null || m_collideBox == null) {
			return;
		}
		if (this == ((GameScene) m_scene).m_controlledActor) {
			m_posX = Tools.limit(m_posX, 0 - m_collideBox[0], m_scene.m_bgWidth - m_collideBox[2]);
			m_posY = Tools.limit(m_posY, 0 - m_collideBox[1], m_scene.m_bgHeight - m_collideBox[3]);
		}
	}

	// private int m_index_frame_test = 0;
	public void drawAnimations(Graphics g, int camX, int camY)
	{
		if (m_anims == null || m_anims.length == 0)
			return;
		int x = m_posX - camX;
		int y = m_posY - camY;
		try {
			for (int i = 0; i < m_anims.length; i++) {
				if (m_anims[i] != null) {
					if (i == 2 && (m_anims[1] == GameManager.getInstance().m_shadowAnimation)) {
						
					}
					else {
						m_anims[i].draw(g, x, y, m_flipX, m_flipY, m_frameIndex);
					}
				}
			}
			
		}
		catch (Exception ex) {
			Tools.debug(ex);
		}
	}

	/**
	 * 绘制
	 */
	public synchronized void draw(Graphics g, int camX, int camY)
	{
		if (m_viewpriority != 0) {// 显示等级最低时不显示影子
			// 阴影
			switch (m_actionIDNow / DIRECT_NUM) {
				case ACTION_DEAD1:
				case ACTION_DEAD2:
				case ACTION_DEAD3:
				case ACTION_DEAD4:
					break;
				default:
					if (m_collideBox != null) {
						g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
						Tools.fillArc(g, GameManager.COLOR_ACTOR_SHADOW, m_posX - camX + m_collideBox[0] * 2, m_posY
								- camY + m_collideBox[1], (m_collideBox[2] - m_collideBox[0]) * 2,
								m_collideBox[3] - m_collideBox[1], 0, 360);
					}
					break;
			}
		}

		if (m_viewpriority == 2) {// 显示等级最高时有形象
			super.draw(g, camX, camY);
		}

		// 名字 显示优先级不是最低都显示名字
		if (m_viewpriority != 0 && m_name != null && m_activeBox != null) {
			g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
			int src_h = 0;
			if (m_isride && m_ride != null) {
				switch (m_ride.m_rideType) {
					case ActorItemRide.TYPE_GROUND:
						src_h = 18;
						break;
					case ActorItemRide.TYPE_SKY:
						src_h = 36;
						break;
					default:
						break;
				}
			}
			if (m_status == ActorRole.ACTOR_STATUS_ROLE_DEAD) {
				src_h = m_activeBox[1];
			}

			if (checkTargetFriend(GameManager.getInstance().m_role)) {
				if (m_battlefield_flag > 0) {
					AbstractGameScreen.drawRegion(g, GameScene.s_img_icon,
							(BATTLEFIELD_FLAG % GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[0],
							(BATTLEFIELD_FLAG / GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[1],
							GameScene.SIZE_IMG_ICON[0], GameScene.SIZE_IMG_ICON[1], 0, m_posX - camX,
							m_posY - camY + m_activeBox[1] - src_h - AbstractGameScreen.FONT_H, Tools.HCENTER_BOTTOM);
				}
				else {
					if (m_appellation != null && !m_appellation.equals("")) {
						Tools.drawString(g, APPELLATION_COLOR[m_appellation_color], Tools.BLACK, m_appellation, m_posX
								- camX, m_posY - camY + m_activeBox[1] - src_h
								- AbstractGameScreen.FONT_H, Tools.HCENTER_BOTTOM);
						if (m_family_name != null) {
							Tools.drawString(g, FAMILY_NAME_COLOR, Tools.BLACK, m_family_name, m_posX - camX, m_posY
									- camY + m_activeBox[1] - src_h
									- (AbstractGameScreen.FONT_H << 1), Tools.HCENTER_BOTTOM);
						}
					}
					else {
						if (m_family_name != null) {
							Tools.drawString(g, FAMILY_NAME_COLOR, Tools.BLACK, m_family_name, m_posX - camX, m_posY
									- camY + m_activeBox[1] - src_h - AbstractGameScreen.FONT_H,
									Tools.HCENTER_BOTTOM);
						}
					}

				}
				Tools.drawString(g, Tools.WHITE, Tools.BLACK, m_name, m_posX - camX, m_posY - camY + m_activeBox[1]
						- src_h, Tools.HCENTER_BOTTOM);
			}
			else {
				if (m_battlefield_flag > 0) {
					AbstractGameScreen.drawRegion(g, GameScene.s_img_icon,
							(BATTLEFIELD_FLAG % GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[0],
							(BATTLEFIELD_FLAG / GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[1],
							GameScene.SIZE_IMG_ICON[0], GameScene.SIZE_IMG_ICON[1], 0, m_posX - camX,
							m_posY - camY + m_activeBox[1] - src_h - AbstractGameScreen.FONT_H, Tools.HCENTER_BOTTOM);
				}
				else {
					if (m_appellation != null && !m_appellation.equals("")) {
						Tools.drawString(g, APPELLATION_COLOR[m_appellation_color], Tools.BLACK, m_appellation, m_posX
								- camX, m_posY - camY + m_activeBox[1] - src_h
								- AbstractGameScreen.FONT_H, Tools.HCENTER_BOTTOM);
						if (m_family_name != null) {
							Tools.drawString(g, FAMILY_NAME_COLOR, Tools.BLACK, m_family_name, m_posX - camX, m_posY
									- camY + m_activeBox[1] - src_h
									- (AbstractGameScreen.FONT_H << 1), Tools.HCENTER_BOTTOM);
						}
					}
					else {
						if (m_family_name != null) {
							Tools.drawString(g, FAMILY_NAME_COLOR, Tools.BLACK, m_family_name, m_posX - camX, m_posY
									- camY + m_activeBox[1] - src_h - AbstractGameScreen.FONT_H,
									Tools.HCENTER_BOTTOM);
						}
					}
				}
				Tools.drawString(g, Tools.RED, Tools.BLACK, m_name, m_posX - camX, m_posY - camY + m_activeBox[1]
						- src_h, Tools.HCENTER_BOTTOM);
			}
			if (m_faction == FACTION_1) {
				g.drawImage(GameScene.s_img_z_icon[GameScene.ZHEN_ICON_KL], m_posX - camX
						- (AbstractGameScreen.s_font.stringWidth(m_name) >> 1) - 3, m_posY - camY
						+ m_activeBox[1] - src_h - (AbstractGameScreen.FONT_H >> 1), Tools.RIGHT_VCENTER);
			}
			else if (m_faction == FACTION_2) {
				g.drawImage(GameScene.s_img_z_icon[GameScene.ZHEN_ICON_TS], m_posX - camX
						- (AbstractGameScreen.s_font.stringWidth(m_name) >> 1) - 3, m_posY - camY
						+ m_activeBox[1] - src_h - (AbstractGameScreen.FONT_H >> 1), Tools.RIGHT_VCENTER);
			}
			else if (m_faction == FACTION_3) {
				g.drawImage(GameScene.s_img_z_icon[GameScene.ZHEN_ICON_DT], m_posX - camX
						- (AbstractGameScreen.s_font.stringWidth(m_name) >> 1) - 3, m_posY - camY
						+ m_activeBox[1] - src_h - (AbstractGameScreen.FONT_H >> 1), Tools.RIGHT_VCENTER);
			}
			if (m_vip_lv > 0 && GameScene.s_img_v_icon != null && m_vip_lv - 1 < GameScene.s_img_v_icon.length) {
				if (m_faction != FACTION_1 && m_faction != FACTION_2 && m_faction != FACTION_3) {
					g.drawImage(GameScene.s_img_v_icon[m_vip_lv - 1], m_posX - camX
							- (AbstractGameScreen.s_font.stringWidth(m_name) >> 1) - 3, m_posY - camY + m_activeBox[1]
							- src_h - (AbstractGameScreen.FONT_H >> 1), Tools.RIGHT_VCENTER);
				}
				else {
					g.drawImage(GameScene.s_img_v_icon[m_vip_lv - 1], m_posX - camX
							- (AbstractGameScreen.s_font.stringWidth(m_name) >> 1) - 4 - GameScene.SIZE_IMG_ICON[0],
							m_posY
									- camY + m_activeBox[1] - src_h - (AbstractGameScreen.FONT_H >> 1),
							Tools.RIGHT_VCENTER);
				}
			}
		}
	}

	/**
	 * 克隆对象
	 */
	public Actor clone(Actor actor)
	{
		ActorRole ca = new ActorRole();
		ca.m_scene = actor.m_scene;
		ca.m_anims = new Animation[actor.m_anims.length];
		System.arraycopy(actor.m_anims, 0, ca.m_anims, 0, actor.m_anims.length);
		ca.m_anim = actor.m_anim;
		ca.m_actionIDNow = actor.m_actionIDNow;
		ca.m_actionIDBefore = actor.m_actionIDBefore;
		ca.m_frameId = actor.m_frameId;
		ca.m_frameIndex = actor.m_frameIndex;
		ca.m_frameDuration = actor.m_frameDuration;
		ca.m_actionCycle = actor.m_actionCycle;
		ca.m_actionOver = actor.m_actionOver;
		ca.m_layer = actor.m_layer;
		ca.m_phylayer = actor.m_phylayer;
		ca.m_flag = actor.m_flag;
		ca.m_flipX = actor.m_flipX;
		ca.m_flipY = actor.m_flipY;
		ca.m_visible = actor.m_visible;
		ca.m_enabled = actor.m_enabled;
		ca.m_needDraw = actor.m_needDraw;
		ca.m_posX = actor.m_posX;
		ca.m_posY = actor.m_posY;
		ca.m_vX = actor.m_vX;
		ca.m_vY = actor.m_vY;
		ca.m_collideBox = new short[actor.m_collideBox.length];
		System.arraycopy(actor.m_collideBox, 0, ca.m_collideBox, 0, actor.m_collideBox.length);
		ca.m_activeBox = new short[actor.m_activeBox.length];
		System.arraycopy(actor.m_activeBox, 0, ca.m_activeBox, 0, actor.m_activeBox.length);
		ca.m_parameters = new short[actor.m_parameters.length];
		System.arraycopy(actor.m_parameters, 0, ca.m_parameters, 0, actor.m_parameters.length);
		return ca;
	}

	public void reset()
	{
		m_scene = null;
		m_targetActor = null;
	}

	/**
	 * 释放
	 */
	public void dispose()
	{
		super.dispose();
		if (m_roleTeam != null) {
			m_roleTeam.removeAllElements();
		}
		if (m_bag_equipment != null) {
			for (int i = 0; i < m_bag_equipment.length; i++) {
				m_bag_equipment[i] = null;
			}
		}
		if (m_bag_goods != null) {
			for (int i = 0; i < m_bag_goods.length; i++) {
				m_bag_goods[i] = null;
			}
		}
		m_drama_list.removeAllElements();
		m_event_list.removeAllElements();
	}

	/**
	 * 深度销毁
	 */
	public void destroy()
	{
		super.destroy();
		if (m_roleTeam != null) {
			m_roleTeam.removeAllElements();
		}
		if (m_bag_equipment != null) {
			for (int i = 0; i < m_bag_equipment.length; i++) {
				m_bag_equipment[i] = null;
			}
		}
		if (m_bag_goods != null) {
			for (int i = 0; i < m_bag_goods.length; i++) {
				m_bag_goods[i] = null;
			}
		}
		m_drama_list.removeAllElements();
		m_event_list.removeAllElements();
	}
    //zuobi 挂机
//	public static final int PICK_ITEM_RANGE = 80 * 80;
	public static final int PICK_ITEM_RANGE = 20 * 20;
	public static final int PICK_ITEM_PROTECT_TIME = 50;

	public Vector m_pickItem_IDs; // 已拾取道具ID列表
	public int m_pickItem_protectTime; // 拾取道具保护时间（用于屏蔽因为背包满而导致的反复拾取）

	// ////////////////////////////////////////////////////////
	// //////组队
	// ////////////////////////////////////////////////////////

	/**
	 * 获取全队的信息
	 * 
	 * @param dis
	 * @throws IOException
	 */
	// public void recvTeamInfo(DataInputStream dis) throws IOException
	// {
	// // GameManager.getInstance().m_game_message.unlockNetwork();
	// short status = dis.readShort(); //0失败 1成功
	// String hint = dis.readUTF(); //提示信息
	// if (status == 0) {
	// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
	// hint);
	// return;
	// }
	// GameManager.getInstance().m_role.m_teamID = dis.readLong(); //队伍的ＩＤ
	// if (GameManager.getInstance().m_role.m_teamID == 0) { //队伍ＩＤ为０读到此处
	// GameManager.getInstance().m_role.m_leaderID = -1;
	// GameManager.getInstance().m_role.m_roleTeam = null;
	// return;
	// }
	// GameManager.getInstance().m_role.m_leaderID = dis.readLong(); // 队长的ＩＤ
	// Tools.debugPrintln("组队 队长的ＩＤ" + m_leaderID);
	// Tools.debugPrintln("队伍的ＩＤ" + m_teamID);
	//
	// m_roleTeam = new ArrayList();
	// m_roleTeam.removeAllElements();
	// int Numplayer = dis.readInt(); // 队员的数量
	// Tools.debugPrintln("组队 队员的数量" + Numplayer);
	// for (int i = 0; i < Numplayer; i++) {
	// long id = dis.readLong();
	//
	// // ActorRole m_role = (ActorRole)
	// // m_scene.getActorById(AbstractGameActor.ACTOR_TYPE_ROLE,
	// // id);
	// ActorRole teamrole = new ActorRole();
	//
	// // if (m_role == null) {
	// teamrole.m_gameID = id;
	// Tools.debugPrintln("id = " + teamrole.m_gameID);
	// teamrole.m_online = dis.readByte() == 0 ? true : false;// 是否在线 0在线// 1不在线
	// if (teamrole.m_online) {
	// teamrole.m_name = dis.readUTF();
	// teamrole.m_grade = dis.readInt();
	// teamrole.m_race = dis.readByte(); //种族
	// short size = dis.readShort();
	// teamrole.m_vocation = new byte[size];
	// for (short j = 0; j < size; j++) {
	// teamrole.m_vocation[j] = dis.readByte();
	// }
	// }
	// m_roleTeam.addElement(teamrole);
	// Tools.debugPrintln("name = " + teamrole.m_name);
	// Tools.debugPrintln("grade = " + teamrole.m_grade);
	// Tools.debugPrintln("m_race = " + teamrole.m_race);
	// // }
	// }
	// }

	// /**
	// * 队伍变更
	// * @param dis
	// * @throws IOException
	// */
	// public void recvTeamLeaderChange(DataInputStream dis) throws IOException
	// {
	// Tools.debugPrintln("325: 队伍变更指令");
	// GameManager.getInstance().m_role.m_teamID = dis.readLong(); //队伍ID
	// GameManager.getInstance().m_role.m_leaderID = dis.readLong();//队长ID
	// if (GameManager.getInstance().m_role.m_leaderID == 0) {
	// GameManager.getInstance().m_role.m_roleTeam = new ArrayList();
	// GameManager.getInstance().m_role.m_roleTeam.removeAllElements();
	// return;
	// }
	// Tools.debugPrintln("队伍id" + GameManager.getInstance().m_role.m_teamID);
	// Tools.debugPrintln("队长ID" + GameManager.getInstance().m_role.m_leaderID);
	// GameManager.getInstance().m_role.m_roleTeam = new ArrayList();
	// GameManager.getInstance().m_role.m_roleTeam.removeAllElements();
	// int memberNum = dis.readInt(); //队员数量
	// Tools.debugPrintln("队员数量" + memberNum);
	// synchronized (GameManager.getInstance().m_role.m_roleTeam) {
	// for (int i = 0; i < memberNum; i++) {
	// ActorRole teamrole = new ActorRole();
	// teamrole.m_gameID = dis.readLong(); //队员ID
	// Tools.debugPrintln("队员id" + teamrole.m_gameID);
	// teamrole.m_online = ((dis.readByte() == 0) ? true : false);// 是否在线 0在线//
	// 1不在线
	// Tools.debugPrintln("是否在线" + teamrole.m_online);
	// if (teamrole.m_online) {
	//
	// teamrole.m_name = dis.readUTF(); //名字
	// teamrole.m_sex = dis.readByte();//性别
	// teamrole.m_grade = dis.readInt(); //等级
	//
	// Tools.debugPrintln("队员名字：" + teamrole.m_name);
	// Tools.debugPrintln("等级：" + teamrole.m_grade);
	// Tools.debugPrintln("性别：" + teamrole.m_sex);
	//
	// //职业
	// short size = dis.readShort();
	// teamrole.m_vocation = new byte[size];
	// for (short j = 0; j < size; j++) {
	// teamrole.m_vocation[j] = dis.readByte();
	// }
	// }
	// GameManager.getInstance().m_role.m_roleTeam.addElement(teamrole);
	// }
	// }
	// }

	public void recvTeamLeaderChange(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("325: 队伍变更指令");
		byte type = dis.readByte(); //
		Tools.debugPrintln("队伍变更类型： " + type);
		long targetID; // 离队队员ID
		Vector teamVector = GameManager.getInstance().m_role.m_roleTeam;
		switch (type) {
			case 1: // 新建队伍
				teamVector.removeAllElements();
				GameManager.getInstance().m_role.m_teamID = dis.readLong(); // 队伍ID
				GameManager.getInstance().m_role.m_leaderID = dis.readLong();// 队长ID
				int memberNum = dis.readInt(); // 队员数量
				Tools.debugPrintln("队员数量" + memberNum);
				for (int i = 0; i < memberNum; i++) {
					ActorRole teamrole = new ActorRole();
					teamrole.m_gameID = dis.readLong(); // 队员ID
					Tools.debugPrintln("队员id" + teamrole.m_gameID);
					teamrole.m_online = ((dis.readByte() == 0) ? true : false);// 是否在线
																				// 0在线//
																				// 1不在线
					Tools.debugPrintln("是否在线" + teamrole.m_online);
					if (teamrole.m_online) {
						teamrole.m_name = dis.readUTF(); // 名字
						teamrole.m_sex = dis.readByte();// 性别
						teamrole.m_grade = dis.readInt(); // 等级

						Tools.debugPrintln("队员名字：" + teamrole.m_name);
						Tools.debugPrintln("等级：" + teamrole.m_grade);
						Tools.debugPrintln("性别：" + teamrole.m_sex);

						// 职业
						short size = dis.readShort();
						teamrole.m_vocation = new byte[size];
						for (short j = 0; j < size; j++) {
							teamrole.m_vocation[j] = dis.readByte();
						}
					}
					teamVector.addElement(teamrole);
				}
				break;
			case 2: // 解散队伍
				GameManager.getInstance().m_role.m_teamID = 0;
				GameManager.getInstance().m_role.m_leaderID = 0;
				teamVector.removeAllElements();
				break;
			case 3: // 上线
				teamVector.removeAllElements();
				GameManager.getInstance().m_role.m_teamID = dis.readLong(); // 队伍ID
				GameManager.getInstance().m_role.m_leaderID = dis.readLong();// 队长ID
				int memberNum3 = dis.readInt(); // 队员数量
				Tools.debugPrintln("队员数量" + memberNum3);
				for (int i = 0; i < memberNum3; i++) {
					ActorRole teamrole = new ActorRole();
					teamrole.m_gameID = dis.readLong(); // 队员ID
					Tools.debugPrintln("队员id" + teamrole.m_gameID);
					teamrole.m_online = ((dis.readByte() == 0) ? true : false);// 是否在线
																				// 0在线//
																				// 1不在线
					Tools.debugPrintln("是否在线" + teamrole.m_online);
					if (teamrole.m_online) {
						teamrole.m_name = dis.readUTF(); // 名字
						teamrole.m_sex = dis.readByte();// 性别
						teamrole.m_grade = dis.readInt(); // 等级

						Tools.debugPrintln("队员名字：" + teamrole.m_name);
						Tools.debugPrintln("等级：" + teamrole.m_grade);
						Tools.debugPrintln("性别：" + teamrole.m_sex);

						// 职业
						short size = dis.readShort();
						teamrole.m_vocation = new byte[size];
						for (short j = 0; j < size; j++) {
							teamrole.m_vocation[j] = dis.readByte();
						}
					}
					teamVector.addElement(teamrole);
				}
				break;
			case 4: // 下线
				targetID = dis.readLong(); // 离线成员ID
				if (teamVector == null) {
					break;
				}
				for (int i = 0, size = teamVector.size(); i < size; i++) {
					ActorRole role = (ActorRole) teamVector.elementAt(i);
					if (role.m_gameID == targetID) {
						role.m_online = false;
					}
				}
				break;
			case 5: // 入队
				teamVector.removeAllElements();
				GameManager.getInstance().m_role.m_teamID = dis.readLong(); // 队伍ID
				GameManager.getInstance().m_role.m_leaderID = dis.readLong();// 队长ID
				int memberNum2 = dis.readInt(); // 队员数量
				Tools.debugPrintln("队员数量" + memberNum2);
				for (int i = 0; i < memberNum2; i++) {
					ActorRole teamrole = new ActorRole();
					teamrole.m_gameID = dis.readLong(); // 队员ID
					Tools.debugPrintln("队员id" + teamrole.m_gameID);
					teamrole.m_online = ((dis.readByte() == 0) ? true : false);// 是否在线
																				// 0在线//
																				// 1不在线
					Tools.debugPrintln("是否在线" + teamrole.m_online);
					if (teamrole.m_online) {
						teamrole.m_name = dis.readUTF(); // 名字
						teamrole.m_sex = dis.readByte();// 性别
						teamrole.m_grade = dis.readInt(); // 等级

						Tools.debugPrintln("队员名字：" + teamrole.m_name);
						Tools.debugPrintln("等级：" + teamrole.m_grade);
						Tools.debugPrintln("性别：" + teamrole.m_sex);

						// 职业
						short size = dis.readShort();
						teamrole.m_vocation = new byte[size];
						for (short j = 0; j < size; j++) {
							teamrole.m_vocation[j] = dis.readByte();
						}
					}
					teamVector.addElement(teamrole);
				}
				break;
			case 6: // 离队
				targetID = dis.readLong(); // 离队成员ID
				if (targetID == GameManager.getInstance().m_role.m_gameID) {
					teamVector.removeAllElements();
					break;
				}
				for (int i = 0; i < teamVector.size(); i++) {
					long roleID = ((ActorRole) teamVector.elementAt(i)).m_gameID;
					if (targetID == roleID) {
						teamVector.removeElementAt(i);
					}
				}
				break;
			case 7: // 队长变更
				GameManager.getInstance().m_role.m_leaderID = dis.readLong();
				break;
		}
	}

	// //////////////////////////////////////////////////////////////////
	/**
	 * 拾取道具
	 */
	public void pickItem()
	{
		if (m_pickItem_protectTime > 0) {
			m_pickItem_protectTime--;
			return;
		}
		AbstractGameActor actor;
		ActorNPC item;
		for (int i = 0; i < m_scene.m_dynamic_actors.size(); i++) {
			actor = (AbstractGameActor) m_scene.m_dynamic_actors.elementAt(i);
			if (actor == null || actor.m_type != ACTOR_TYPE_ITEM || !actor.m_enabled)
				continue;
			if (Tools.distanceSquare(m_posX, m_posY, actor.m_posX, actor.m_posY) <= PICK_ITEM_RANGE) {
				item = (ActorNPC) actor;
				Long id = new Long(item.m_gameID);
				synchronized (item) {
					if (item.m_relatedActorsID == null || item.m_relatedActorsID.length == 0
							|| Tools.isInArray(m_gameID, item.m_relatedActorsID)) {
						if (!m_pickItem_IDs.contains(id)) {
							m_pickItem_IDs.addElement(id);
							GameManager.getInstance().m_game_message.sendPickUpItem(item.m_gameID);
							Tools.debugPrintln("拾取道具：" + item.m_gameID);
						}
					}
				}
			}
		}
	}

	/**
	 * 施法计时
	 */
	public void castingTimeTick()
	{
		if (m_castingTimeCounter > 0) {
			m_castingTimeCounter--;
		}
	}

	// ////////////////////////////////////////////////////////////
	// // 战斗技能相关
	public RoleCombatSkill[][] m_roleCombatSkill; // 当前玩家角色的技能列表（包括未学习的）
	// public RoleCombatSkill m_curCombatSkill; //当前技能
	public int m_combatSkillPoint = 0; // 当前技能点
	public int m_combatSkillMaxPoint = 0; // 最大技能点

	public int m_publicCD_skill; // 技能公共CD
	public int m_publicCD_skill_counter; // 技能公共CD计时器
	public int m_castingTimeCounter; // 施法计时器
	public int m_castingTime; // 施法时间
	public String m_castingContent; // 施法内容
	public String m_castingContentArray; // 施法内容切分成的数组

	public RoleCombatSkill m_buffer_skill = null;// 缓存技能
	public int m_buffer_time = 0;// 缓存时间
	public final int AUTO_ATTACK_TIME = 20;// 自动攻击间隔时间

	private final int MAXNUM_SKILL = 2;

	/**
	 * 初始化技能
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void initCombatSkill(DataInputStream dis) throws IOException
	{
		disposeCombatSkill();
		// Tools.debugPrintln("获得技能列表数据~~开始");
		m_combatSkillMaxPoint = dis.readShort();// 最大点数
		m_combatSkillPoint = dis.readShort();// 剩余点数
		int num = dis.readByte();// 技能类别长度 默认0-4
		int num_skill = 0;// 技能列表数目
		int num_genius = 0;// 天赋列表数目
		RoleCombatSkill[] skills = new RoleCombatSkill[num];
		for (int i = 0; i < num; i++) {
			// 获得技能信息
			skills[i] = new RoleCombatSkill();
			skills[i].read(dis);
			if (skills[i].m_id == -1) {
				skills[i] = null;
				continue;
			}
			// 获得技能类别数目
			switch (skills[i].m_type_skill) {
				case RoleCombatSkill.TYPE_SKILL_GENIUS:
					num_genius++;
					break;
				default:
					num_skill++;
					break;
			}
		}
		// 初始化技能列表
		m_roleCombatSkill = null;
		m_roleCombatSkill = new RoleCombatSkill[MAXNUM_SKILL][];
		m_roleCombatSkill[RoleCombatSkill.INDEX_COMBATSKILL_SKILL] = new RoleCombatSkill[num_skill];
		m_roleCombatSkill[RoleCombatSkill.INDEX_COMBATSKILL_GENIUS] = new RoleCombatSkill[num_genius];
		int index_skill = 0;// 技能列表索引
		int index_genius = 0;// 天赋列表索引
		// 将数据放入到技能列表中
		for (int i = 0; i < skills.length; i++) {
			if (skills[i] == null) {
				continue;
			}
			switch (skills[i].m_type_skill) {
				case RoleCombatSkill.TYPE_SKILL_GENIUS:
					m_roleCombatSkill[RoleCombatSkill.INDEX_COMBATSKILL_GENIUS][index_genius++] = skills[i];
					break;
				default:
					m_roleCombatSkill[RoleCombatSkill.INDEX_COMBATSKILL_SKILL][index_skill++] = skills[i];
					break;
			}
		}
		// Tools.debugPrintln("获得技能列表数据~~结束");
	}

	public void setCombatSKill(DataInputStream dis) throws IOException
	{
		ActorRole role = GameManager.getInstance().m_role;
		role.m_combatSkillMaxPoint = dis.readShort();
		role.m_combatSkillPoint = dis.readShort();
		// Tools.debugPrintln("m_combatSkillMaxPoint = "+
		// role.m_combatSkillMaxPoint);
		// Tools.debugPrintln("m_combatSkillPoint = " +
		// role.m_combatSkillPoint);
		int oldId = dis.readShort();
		for (int i = 0; i < role.m_roleCombatSkill.length; i++) {
			for (int ii = 0; ii < role.m_roleCombatSkill[i].length; ii++) {
				if (role.m_roleCombatSkill[i][ii].m_id == oldId) {
					role.m_roleCombatSkill[i][ii] = null;
					role.m_roleCombatSkill[i][ii] = new RoleCombatSkill();
					role.m_roleCombatSkill[i][ii].read(dis);
					// Tools.debugPrintln("修改快捷栏,当技能发生改变时");
					// 改变快捷栏
					if (role.m_roleCombatSkill[i][ii].m_level <= 0) {// 等级为0
						GameManager.getInstance().m_role.cleanShortcut(AbstractGameActor.ACTION_TYPE_SKILL, oldId);
					}
					else {
						GameManager.getInstance().m_role.resetShortcut(AbstractGameActor.ACTION_TYPE_SKILL, oldId,
								role.m_roleCombatSkill[i][ii].m_id);
					}
					// 更新宏
					UIMain.updateMarco(oldId, role.m_roleCombatSkill[i][ii].m_id, i, ii);
					return;
				}
			}
		}
	}

	/**
	 * 清空战斗技能列表
	 */
	public void disposeCombatSkill()
	{
		if (m_roleCombatSkill != null) {
			for (int i = 0; i < m_roleCombatSkill.length; i++) {
				if (m_roleCombatSkill[i] != null) {
					for (int ii = 0; ii < m_roleCombatSkill[i].length; ii++) {
						if (m_roleCombatSkill[i][ii] != null) {
							m_roleCombatSkill[i][ii].dispose();
							m_roleCombatSkill[i][ii] = null;
						}
					}
					m_roleCombatSkill[i] = null;
				}
			}
			m_roleCombatSkill = null;
		}
	}

	/**
	 * 根据id获得对应的技能
	 * 
	 * @param id
	 * @return
	 */
	public RoleCombatSkill getCombatSkill(short id)
	{
		for (int i = 0; i < m_roleCombatSkill.length; i++) {
			if(m_roleCombatSkill[i] == null){
				continue;
			}
			for (int ii = 0; ii < m_roleCombatSkill[i].length; ii++) {
				if (m_roleCombatSkill[i][ii] == null) {
					continue;
				}
				if (m_roleCombatSkill[i][ii].m_id == id) {
					return m_roleCombatSkill[i][ii];
				}
			}
		}
		return null;
	}

	// /**
	// * 根据服务器传过来的流更新技能信息
	// *
	// * @param dis
	// * @throws IOException
	// */
	// public void updateCombatSkill(DataInputStream dis) throws IOException
	// {
	// int id = dis.readShort();
	// RoleCombatSkill skill = new RoleCombatSkill();
	// skill.read(dis);
	// for (int i = 0; i < m_roleCombatSkill.length; i++)
	// for (int ii = 0; ii < m_roleCombatSkill[i].length; ii++) {
	// if (m_roleCombatSkill[i][ii].m_id == id) {
	// m_roleCombatSkill[i][ii].dispose();
	// m_roleCombatSkill[i][ii] = null;
	// m_roleCombatSkill[i][ii] = skill;
	// }
	// }
	// }

	/**
	 * 使用技能
	 * 
	 * @param m_id_int
	 */
	public void useCombatSkill(RoleCombatSkill skill)
	{
		if (skill == null)
			return;
		m_curCombatSkill = skill;
		int info = m_posX | (m_posY << 16);
		m_pathPoint.addElement(new Integer(info));
		GameManager.getInstance().m_game_message.sendMove(m_type, m_pathPoint);
		m_pathPoint.removeAllElements();
		switch (skill.m_type) {
			case RoleCombatSkill.TYPE_COMMON: {
				if (skill.m_castSrcActionId >= 0) {
					if (m_targetActor != null) {
						changeDirectToTarget(m_targetActor);
					}
					Tools.debugPrintln("施放瞬发技能");
					setAction(skill.m_castSrcActionId * DIRECT_NUM + m_direct, 0, 0, false, true);
					((GameScene) m_scene).addEffect(skill.m_castSrcEffectId, m_posX, m_posY);
					// 没有目标的话，发送自己的type和ID
					if (m_targetActor != null) {
						GameManager.getInstance().m_game_message.sendCastSkill(skill.m_id, m_targetActor.m_type,
								m_targetActor.m_gameID);
					}
					else {
						GameManager.getInstance().m_game_message.sendCastSkill(skill.m_id, m_type, m_gameID);
					}
				}
				else {
					Tools.debugPrintln("瞬发或者通道法术的施法动作为空");
				}
				break;
			}
			case RoleCombatSkill.TYPE_CONTINUOUS: {
				if (skill.m_castSrcActionId >= 0) {
					m_isCasting = true;
					startCasting(((RoleCombatSkill) m_curCombatSkill).m_castingTime);
					startCastingDescription(((RoleCombatSkill) m_curCombatSkill).m_name);
					if (m_targetActor != null) {
						changeDirectToTarget(m_targetActor);
					}
					Tools.debugPrintln("施放通道技能");
					setAction(skill.m_castSrcActionId * DIRECT_NUM + m_direct, 0, 0, false, true);
					((GameScene) m_scene).addEffect(skill.m_castSrcEffectId, m_posX, m_posY);
					// 没有目标的话，发送自己的type和ID
					if (m_targetActor != null) {
						GameManager.getInstance().m_game_message.sendCastSkill(skill.m_id, m_targetActor.m_type,
								m_targetActor.m_gameID);
					}
					else {
						GameManager.getInstance().m_game_message.sendCastSkill(skill.m_id, m_type, m_gameID);
					}
				}
				else {
					Tools.debugPrintln("瞬发或者通道法术的施法动作为空");
				}
				break;
			}
			case RoleCombatSkill.TYPE_SING: {
				if (skill.m_singActionId >= 0) {
					m_isCasting = true;
					startCasting(((RoleCombatSkill) m_curCombatSkill).m_castingTime);
					startCastingDescription(((RoleCombatSkill) m_curCombatSkill).m_name);
					m_castingTimeCounter = ((RoleCombatSkill) m_curCombatSkill).m_castingTime;
					m_castingTime = ((RoleCombatSkill) m_curCombatSkill).m_castingTime;
					if (m_targetActor != null) {
						changeDirectToTarget(m_targetActor);
					}
					Tools.debugPrintln("吟唱技能");
					setAction(skill.m_singActionId * DIRECT_NUM + m_direct, 0, 0, true, true);
					m_castSrcEffect = ((GameScene) m_scene).addEffect(skill.m_singEffectId, m_posX, m_posY,
							Integer.MAX_VALUE, true);
					// 没有目标的话，发送自己的type和ID
					if (m_targetActor != null) {
						GameManager.getInstance().m_game_message.sendCastSkill(skill.m_id, m_targetActor.m_type,
								m_targetActor.m_gameID);
					}
					else {
						GameManager.getInstance().m_game_message.sendCastSkill(skill.m_id, m_type, m_gameID);
					}
				}
				else {
					Tools.debugPrintln("吟唱法术的吟唱动作为空");
				}
				break;
			}
		}

		m_publicCD_skill = skill.m_publicCD;
		m_publicCD_skill_counter = skill.m_publicCD;
		skill.m_cd_counter = skill.m_cd;
		if (m_followTarget) {
			clearFollowTarget();
		}
		if (m_pathfinding_start && !m_pathfinding_pause) {
			clearPathfinding();
		}
		// if (!m_combat_status) {
		// m_combat_status = true;
		// m_combat_exit_time = COMBAT_EXIT_TIME;
		// }
	}

	// /**
	// * 检测目标周围碰撞
	// *
	// * @param target
	// */
	// private void changeTargetAround(AbstractGameActor target)
	// {
	// if (target == null)
	// return;
	// Background bg = GameManager.getInstance().m_scene.m_bg;
	// byte index = 0;
	// if (target.m_posY < m_posY && target.m_posX < m_posX) {// 在右下
	// Tools.debugPrintln("右下!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_RD);
	// }
	// else if (target.m_posX < m_posX) {// 在右上
	// Tools.debugPrintln("右上!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_RU);
	// }
	// else if (target.m_posY < m_posY) {// 在左下
	// Tools.debugPrintln("左下!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_LD);
	// }
	// else {// 在左上
	// Tools.debugPrintln("左上!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_LU);
	// }
	// if (index == -1) {
	// m_posX = target.m_posX;
	// m_posY = target.m_posY;
	// }
	// else {
	// m_posX = target.m_posX + bg.m_tileW * MAP_AROUND_COLLIDE[index][0];
	// m_posY = target.m_posY + bg.m_tileH * MAP_AROUND_COLLIDE[index][1];
	// }
	// Tools.debugPrintln("位移索引 : " + index);
	// }

	// /**
	// * 根据地图得到目标周围无碰撞的索引
	// *
	// * @param bg
	// * @param x
	// * @param y
	// * @param dir
	// * @return
	// */
	// private byte getMapAroundCollide(Background bg, int x, int y, byte dir)
	// {
	// byte[] map = bg.getPhyData();
	// for (byte i = 0, j = dir, k = dir; i < (MAP_AROUND_COLLIDE.length >> 1);
	// i++) {
	// int tile = (y / bg.m_tileH + MAP_AROUND_COLLIDE[j][1])
	// * bg.m_columns
	// + (x / bg.m_tileW + MAP_AROUND_COLLIDE[j][0]);
	// if (tile < map.length && map[tile] != 0) {
	// return j;
	// }
	// j = (byte) (--j < 0 ? MAP_AROUND_COLLIDE.length - 1 : j);
	// k = (byte) (++k >= MAP_AROUND_COLLIDE.length ? 0 : k);
	// tile = (y / bg.m_tileH + MAP_AROUND_COLLIDE[k][1]) * bg.m_columns
	// + (x / bg.m_tileW + MAP_AROUND_COLLIDE[k][0]);
	// if (tile < map.length && map[tile] != 0) {
	// return k;
	// }
	// }
	// return -1;
	// }
	//
	// private byte[][] MAP_AROUND_COLLIDE = { { -1, -1 }, { 0, -1 }, { 1, -1 },
	// { 1, 0 }, { 1, 1 }, { 0, 1 }, { -1, 1 }, { -1, 0 } };
	// private final byte AROUND_DIRECT_RD = 4;// 右下
	// private final byte AROUND_DIRECT_RU = 2;// 右上
	// private final byte AROUND_DIRECT_LD = 6;// 左下
	// private final byte AROUND_DIRECT_LU = 0;// 左上

	/**
	 * 是否能施放技能
	 * 
	 * @param skill
	 * @param targets
	 * @return
	 */
	public boolean canUseCombatSkill(RoleCombatSkill skill, AbstractGameActor target)
	{
		if (skill == null)
			return false;
		if (m_curCombatSkill != null || m_isCasting) {
			// ((GameScene) m_scene).addMessage("正在施法中", Tools.RED,
			// Tools.BLACK);
			return false;
		}
		if (m_status == ACTOR_STATUS_ROLE_DEAD) {
			return false;
		}
		if (skill.m_id != CombatSkill.ID_DK_PG
				&& ((m_action & ACTOR_ACTION_FORBIT_SKILL) != 0 || (m_action & ACTOR_ACTION_FORBIT_ATTACK_SKILL) != 0)) {
			if (!skillCanBreakActionLimit(skill)) {
				((GameScene) m_scene).addMessage(SKILL_HINT_SILENT, Tools.RED, Tools.BLACK);
				return false;
			}
		}
		if (!checkTargetAndBuf(skill, target))
			return false;
		if (skill.m_mode != 0 && m_mode != skill.m_mode) {
			((GameScene) m_scene).addMessage(SKILL_HINT_DISSATISFY, Tools.RED, Tools.BLACK);
			return false;
		}
		if (m_publicCD_skill_counter > 0) {
			if (skill.m_id != 10000)
				((GameScene) m_scene).addMessage(SKILL_HINT_GCD, Tools.RED, Tools.BLACK);
			return false;
		}
		if (skill.m_cd_counter > 0) {
			((GameScene) m_scene).addMessage(SKILL_HINT_COOLING, Tools.RED, Tools.BLACK);
			return false;
		}
		if (m_vocation != null) {
			byte voc = m_vocation[m_vocation.length - 1];
			if (voc != VOCATION_WU_ZHE && voc != VOCATION_MENG_JIANG && voc != VOCATION_DOU_SHI
					&& voc != VOCATION_ZHAN_KUANG && voc != VOCATION_TIAN_JIANG
					&& voc != VOCATION_WU_SHENG) {
				if (skill.m_consumption < 0) {
					Tools.debugPrintln("蓝 : " + m_mp + " : " + skill.m_consumption);
					if (m_mp + skill.m_consumption < 0) {
						if (m_vocation[0] == VOCATION_JIAN_KE) {
							((GameScene) m_scene).addMessage(SKILL_HINT_JIANQI, Tools.RED, Tools.BLACK);
						} else {
							((GameScene) m_scene).addMessage(SKILL_HINT_MANA, Tools.RED, Tools.BLACK);
						}
						return false;
					}
				}
			}
		}
		return true;
	}

	/**
	 * 查看技能是否无视控制
	 * 
	 * @param skill
	 * @return
	 */
	public boolean skillCanBreakActionLimit(RoleCombatSkill skill)
	{
		// 如影加成下的影月
		if (skill.m_groupId == 1004) {
			if (checkHasSkill(1032)) {
				return true;
			}
		}
		
		//无视控制
		if (skill.m_castSrcBufLimit == -1)
			return true;
		return false;
	}

	/**
	 * 检查是否学会某技能
	 * 
	 * @param skillGroupId
	 * @return
	 */
	public boolean checkHasSkill(int skillGroupId)
	{
		if (m_roleCombatSkill == null)
			return false;
		for (int i = 0; i < m_roleCombatSkill.length; i++) {
			if (m_roleCombatSkill[i] == null)
				continue;
			for (int ii = 0; ii < m_roleCombatSkill[i].length; ii++) {
				if (m_roleCombatSkill[i][ii] != null && m_roleCombatSkill[i][ii].m_groupId == skillGroupId
						&& m_roleCombatSkill[i][ii].m_level > 0) {
					return true;
				}
			}
		}
		return false;
	}
	
	public RoleCombatSkill getGroupSkill(int skillGroupId)
	{
		if (m_roleCombatSkill == null)
			return null;
		for (int i = 0; i < m_roleCombatSkill.length; i++) {
			if (m_roleCombatSkill[i] == null)
				continue;
			for (int ii = 0; ii < m_roleCombatSkill[i].length; ii++) {
				if (m_roleCombatSkill[i][ii] != null && m_roleCombatSkill[i][ii].m_groupId == skillGroupId
						&& m_roleCombatSkill[i][ii].m_level > 0) {
					return m_roleCombatSkill[i][ii];
				}
			}
		}
		return null;
	}

	private final String SKILL_HINT_CLIENT = "";
	private final String SKILL_HINT_DISSATISFY = "释放条件不满足" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_GCD = "技能未准备好" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_COOLING = "技能未准备好" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_MANA = "法力不足" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_NO_TARGET = "当前无目标" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_INVALID_TARGET = "无效的当前目标" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_DEAD_TARGET = "目标已死亡" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_LIVE_TARGET = "目标未死亡" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_SILENT = "被封印，不能施法" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_DS = "被定身，不能做动作" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_GZ = "被锁足，不能移动" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_JIANQI = "剑气不足" + SKILL_HINT_CLIENT;

	/**
	 * 释放技能是根据目标以及buf状态进行一些判断和处理
	 * 
	 * @param skill
	 * @param target
	 * @return
	 */
	public boolean checkTargetAndBuf(RoleCombatSkill skill, AbstractGameActor target)
	{
		if (target != null && target.m_type != ACTOR_TYPE_MONSTER && target.m_type != ACTOR_TYPE_ROLE) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "无效的当前目标!");
			return false;
		}
		switch (skill.m_targetType) {
			// 以下不需要目标,直接返回true
			case CombatSkill.TARGET_TYPE_ALL:
			case CombatSkill.TARGET_TYPE_ENEMY_ALL:
			case CombatSkill.TARGET_TYPE_FRIEND_ALL:
			case CombatSkill.TARGET_TYPE_S_SURROUND_ALL:
			case CombatSkill.TARGET_TYPE_S_SURROUND_ENEMY:
			case CombatSkill.TARGET_TYPE_S_SURROUND_FRIEND:
			case CombatSkill.TARGET_TYPE_SELF:
			case CombatSkill.TARGET_TYPE_TEAMMATE_ALL:
				// 需要判断自身的buf
				if (!containBuffer(skill.m_castSrcBufLimit)) {
					return false;
				}
				else {
					return true;
				}
				// 目标必须是敌方
			case CombatSkill.TARGET_TYPE_ENEMY_SINGLE:
			case CombatSkill.TARGET_TYPE_T_SURROUND_ENEMY:
			case CombatSkill.TARGET_TYPE_T_LINE_ENEMY:
				if (target == null) {
					((GameScene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				else if (checkTargetFriend(target)) {
					((GameScene) m_scene).addMessage(SKILL_HINT_INVALID_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				else if (target.m_status == ACTOR_STATUS_ROLE_DEAD) {
					((GameScene) m_scene).addMessage(SKILL_HINT_DEAD_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				break;
			// 目标必须是友方死的
			case CombatSkill.TARGET_TYPE_FRIEND_SINGLE_DEAD:
				if (target == null) {
					((GameScene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				else if (!checkTargetFriend(target)) {
					((GameScene) m_scene).addMessage(SKILL_HINT_INVALID_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				else if (target.m_status != ACTOR_STATUS_ROLE_DEAD) {
					((GameScene) m_scene).addMessage(SKILL_HINT_LIVE_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				break;
			// 目标必须是友方活的
			case CombatSkill.TARGET_TYPE_FRIEND_SINGLE:
			case CombatSkill.TARGET_TYPE_T_SURROUND_FRIEND:
				if (target == null) {
					((GameScene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				else if (!checkTargetFriend(target)) {
					((GameScene) m_scene).addMessage(SKILL_HINT_INVALID_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				else if (target.m_status == ACTOR_STATUS_ROLE_DEAD) {
					((GameScene) m_scene).addMessage(SKILL_HINT_DEAD_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				break;
			// 有目标即可
			case RoleCombatSkill.TARGET_TYPE_T_LINE_ALL:
			case RoleCombatSkill.TARGET_TYPE_T_SURROUND_ALL:
				if (target == null) {
					((GameScene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED, Tools.BLACK);
					return false;
				}
				break;
		}
		// if ((m_posX - target.m_posX) * (m_posX - target.m_posX)
		// + (m_posY - target.m_posY) * (m_posY - target.m_posY) > skill.m_range
		// * skill.m_range) {
		// return false;
		// }
		// 需要选中目标的技能要判断距离
		if (!checkTargetDistance(skill, target)) {
			return false;
		}
		// 需要判断自己的buf
		else if (!containBuffer(skill.m_castSrcBufLimit)) {
			return false;
		}
		// 需要选中目标的技能要判断目标的buf
		else if (!target.containBuffer(skill.m_castTgtBufLimit)) {
			return false;
		}
		else {
			return true;
		}
	}

	private final short ID_COMMON_ATTACK = 10000;// 普通攻击ID

	/**
	 * 检查目标是否在技能范围内
	 * 
	 * @param skill
	 * @param target
	 * @return
	 */
	private boolean checkTargetDistance(RoleCombatSkill skill, AbstractGameActor target)
	{
		if (skill.m_range == 0) {
			return true;
		}
		else {
			if ((m_posX - target.m_posX) * (m_posX - target.m_posX) + (m_posY - target.m_posY)
					* (m_posY - target.m_posY) > skill.m_range * skill.m_range) {
				// if (skill.m_id == ID_COMMON_ATTACK && m_status ==
				// ACTOR_STATUS_ROLE_COMBAT) {
				// clearAutoAttack();
				// }
				// else {
				if (!m_auto_pathfinding || !skill.equals(m_auto_skill)) {
					// Background background =
					// GameManager.getInstance().m_scene.m_bg;
					// int targetPos = (target.m_posY >> 4) *
					// background.m_columns + (target.m_posX >> 4);
					// m_auto_paths =
					// BinHeapAStar.findPath(background.getPhyData(),
					// background.m_columns,
					// background.m_rows, (m_posY >> 4) * background.m_columns +
					// (m_posX >> 4), targetPos);
					if (target != null) {
						int targetPos = getAutoPathPos(target.m_posX, target.m_posY);
						m_auto_paths = getAutoPathArray(getAutoPathPos(m_posX, m_posY), targetPos);
						if (m_auto_paths != null && m_auto_paths[m_auto_paths.length - 1] == targetPos) {
							keyAnyStopOther();
							openAutoPathfinding(m_auto_paths, skill, target);
							Tools.debugPrintln("技能自动寻路开始");
						}
						else {
							Tools.debugPrintln("技能自动寻路失败,目标与寻路结果不同!" + m_auto_paths);
						}
					}
				}
				// }
			}
			else {
				return true;
			}
		}
		return false;
	}

	public void findPathToTarget(ActorNPC npc)
	{
		if (isAliveStatus()) {
			int targetPos = getAutoPathPos(npc.m_posX, npc.m_posY);
			m_auto_paths = getAutoPathArray(getAutoPathPos(m_posX, m_posY), targetPos);
			if (m_auto_paths != null && m_auto_paths[m_auto_paths.length - 1] == targetPos) {
				keyAnyStopOther();
				openAutoPathfinding(m_auto_paths, null, npc);
				Tools.debugPrintln("自动寻路到目标开始");
			}
			else {
				Tools.debugPrintln("自动寻路到目标失败,目标与寻路结果不同!" + m_auto_paths);
			}
		}
	}

	/**
	 * 玩家是否活着
	 * @return true没死,false死亡
	 */
	public boolean isAliveStatus()
	{
		if (m_status != AbstractGameActor.ACTOR_STATUS_ROLE_DEAD) {
			return true;
		}
		GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "您已经死亡!");
		return false;
	}

	/**
	 * 将x,y坐标转换成寻路的坐标
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public int getAutoPathPos(int x, int y)
	{
		Background background = GameManager.getInstance().m_scene.m_bg;
		return (y >> 4) * background.m_columns + (x >> 4);
	}

	/**
	 * 得到寻路的数组
	 * 
	 * @param srcPos
	 * 原坐标
	 * @param destPos
	 * 目标坐标
	 * @return
	 */
	public short[] getAutoPathArray(int srcPos, int destPos)
	{
		Background background = GameManager.getInstance().m_scene.m_bg;
		return BinHeapAStar.findPath(background.getPhyData(), background.m_columns, background.m_rows, srcPos, destPos);
	}

	private void autoPathfindingLogic()
	{
		ActorRole role = GameManager.getInstance().m_role;
		Background background = GameManager.getInstance().m_scene.m_bg;
		if (role.m_targetActor == null || !role.m_targetActor.equals(m_auto_target) || m_auto_paths == null) {
			Tools.debugPrintln("目标被移除,自动寻路结束!");
			resetAutoPathfinding();
			return;
		}
		if (m_auto_paths.length <= 1) {
			Tools.debugPrintln("已经到达不需要寻路!");
			resetAutoPathfinding();
			return;
		}
		if (m_auto_index >= m_auto_paths.length) {
			Tools.debugPrintln("寻路移动结束,没有达到目标!");
			int targetPos = (m_auto_target.m_posY >> 4) * background.m_columns + (m_auto_target.m_posX >> 4);
			m_auto_paths = BinHeapAStar.findPath(background.getPhyData(), background.m_columns, background.m_rows,
					(m_posY >> 4) * background.m_columns + (m_posX >> 4), targetPos);
			openAutoPathfinding(m_auto_paths, m_auto_skill, m_auto_target);
			if (m_auto_paths != null && m_auto_paths[m_auto_paths.length - 1] == targetPos) {
				openAutoPathfinding(m_auto_paths, m_auto_skill, m_auto_target);
			}
			else {
				Tools.debugPrintln("目标与寻路结果不同,寻路失败!" + m_auto_paths);
			}
		}
		else {
			if (m_auto_skill == null) {//采集
				if ((m_posX - m_auto_target.m_posX) * (m_posX - m_auto_target.m_posX)
						+ (m_posY - m_auto_target.m_posY) * (m_posY - m_auto_target.m_posY) < (background.m_tileW << 1)
						* (background.m_tileH << 1)) {
					if (m_auto_target.m_type == ActorNPC.ACTOR_TYPE_GATHERING
							|| m_auto_target.m_type == ActorNPC.ACTOR_TYPE_NPC) {
						((GameScene) m_scene).setTargetActor(m_auto_target);
						GameManager.getInstance().m_game_message.sendNPCList(m_auto_target.m_gameID);
					}
					resetAutoPathfinding();
				}
				else {
					int targetX = ((m_auto_paths[m_auto_index] % background.m_columns) * background.m_tileW)
							+ (background.m_tileW >> 1);
					int targetY = ((m_auto_paths[m_auto_index] / background.m_columns) * background.m_tileH)
							+ (background.m_tileH >> 1);
					int dValueX = role.m_posX - targetX;
					int dValueY = role.m_posY - targetY;
					int speed = role.m_velocity >> Actor.ACTOR_FRACTION_BIT;
					if (Tools.abs(dValueX) > speed) {
						if (dValueX > 0) {
							super.move(DIRECT_W);
						}
						else {
							super.move(DIRECT_E);
						}
					}
					else if (Tools.abs(dValueY) > speed) {
						if (dValueY > 0) {
							super.move(DIRECT_N);
						}
						else {
							super.move(DIRECT_S);
						}
					}
					else {
						m_auto_index++;
					}
				}
			}
			else {//技能
				if (role.checkTargetDistance(m_auto_skill, m_auto_target)) {
					if (role.canUseCombatSkill(m_auto_skill, m_auto_target)) {
						role.useCombatSkill(m_auto_skill);
						role.initAutoAttack();
					}
					else {
						role.clearAutoAttack();
					}
					resetAutoPathfinding();
					Tools.debugPrintln("已达到施法范围内,解除自动寻路!");
				}
				else {
					int targetX = ((m_auto_paths[m_auto_index] % background.m_columns) * background.m_tileW)
							+ (background.m_tileW >> 1);
					int targetY = ((m_auto_paths[m_auto_index] / background.m_columns) * background.m_tileH)
							+ (background.m_tileH >> 1);
					int dValueX = role.m_posX - targetX;
					int dValueY = role.m_posY - targetY;
					int speed = role.m_velocity >> Actor.ACTOR_FRACTION_BIT;
					if (Tools.abs(dValueX) > speed) {
						if (dValueX > 0) {
							super.move(DIRECT_W);
						}
						else {
							super.move(DIRECT_E);
						}
					}
					else if (Tools.abs(dValueY) > speed) {
						if (dValueY > 0) {
							super.move(DIRECT_N);
						}
						else {
							super.move(DIRECT_S);
						}
					}
					else {
						m_auto_index++;
					}
				}
			}
		}
	}

	private void openAutoPathfinding(short[] paths, RoleCombatSkill skill, AbstractGameActor target)
	{
		if (paths != null) {
			m_auto_pathfinding = true;
			m_auto_index = 1;
			m_auto_skill = skill;
			m_auto_target = target;
			Tools.debugPrintln("超出范围,启用寻路成功!");
		}
		else {
			Tools.debugPrintln("超出范围,启用寻路失败!");
		}
	}

	private void resetAutoPathfinding()
	{
		m_auto_pathfinding = false;
		m_auto_index = 0;
		m_auto_paths = null;
		m_auto_skill = null;
		m_auto_target = null;
		m_buffer_skill = null;
		m_buffer_time = 0;
	}

	/**
	 * 技能，道具等的cooldown
	 */
	public void cooldown()
	{
		if (m_publicCD_skill_counter > 0) {
			m_publicCD_skill_counter--;
		}
		if (m_roleCombatSkill != null) {
			for (int i = 0; i < m_roleCombatSkill.length; i++) {
				if (m_roleCombatSkill[i] == null)
					continue;
				for (int ii = 0; ii < m_roleCombatSkill[i].length; ii++) {
					if (m_roleCombatSkill[i][ii] != null) {
						m_roleCombatSkill[i][ii].cooldown();
					}
				}
			}
		}
	}

	/**
	 * 角色死亡，进行各种处理
	 */
	public void dead()
	{
		stopCasting();
		stopCastingDescription();
		m_isCasting = false;
	}

	// /**
	// * 快捷栏设置
	// *
	// * @param skills
	// * @return
	// */
	// public RoleCombatSkill[] filterSkillByShortcut(RoleCombatSkill[] skills)
	// {
	// if (skills == null) {
	// return null;
	// }
	// int num = 0;
	// for (int i = 0; i < skills.length; i++) {
	// if (skills[i] == null) {
	// continue;
	// }
	// if (isRoleSkillSetToSkillBar(skills[i])) {
	// num++;
	// }
	// }
	// if (num == 0) {
	// return null;
	// }
	// RoleCombatSkill[] results = new RoleCombatSkill[num];
	// int index = 0;
	// for (int i = 0; i < skills.length; i++) {
	// if (skills[i] == null) {
	// continue;
	// }
	// if (isRoleSkillSetToSkillBar(skills[i])) {
	// results[index] = skills[i];
	// index++;
	// }
	// }
	// return results;
	// }

	// /**
	// * 符合设置到快捷栏的技能
	// * @param skill
	// * @return
	// */
	// public static final boolean isRoleSkillSetToSkillBar(RoleCombatSkill
	// skill)
	// {
	// if (skill.m_level != 0 && skill.m_isLearn && skill.m_type != 3 &&
	// !skill.m_isPassive) {
	// return true;
	// }
	// return false;
	// }

	/**
	 * 玩家站立
	 * 
	 * 2012-2-24 下午06:23:55 venizeng 调用建平代码
	 * 
	 */
	public void stand()
	{
		if (this.m_status != ActorRole.ACTOR_STATUS_ROLE_DEAD) {
			if (this.m_isride) {
				this.setAction((this.m_ride.m_rideType - 1 + ActorRole.ACTION_RIDESTAND1) * ActorRole.DIRECT_NUM
						+ this.m_direct, 0, 0, true, true);
			}
			else {
				this.setAction(ActorRole.ACTION_STAND * ActorRole.DIRECT_NUM + this.m_direct, 0, 0, true, false);
			}
		}
	}

	// // 战斗技能相关
	// ////////////////////////////////////////////////////////////

	// ////////////////////////////////////////////////////////////
	// // 角色行为

	/**
	 * 根据data进行相应的动作
	 * 
	 * @param data
	 */
	public int doAction(Object data)
	{
		if (data == null){
			return MACRO_STATE_EXCEPTION;
		}
		long[] info = (long[]) data;
		int type = (int) info[0];
		long id = info[1];
		byte status = (byte) info[2];
		switch (type) {
			case ACTION_TYPE_SKILL:
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					ActorRole role = GameManager.getInstance().m_role;
					RoleCombatSkill skill = role.getCombatSkill((short) id);
					if (status == MACRO_STATE_READY) {
					 if (role.canUseCombatSkill(skill, role.m_targetActor)) {// 冷却中,播放中,法力不足
						 role.useCombatSkill(skill);
						 role.initAutoAttack();
					     //zuobi 技能
//						if(role.m_targetActor != ((GameScene) m_scene).m_controlledActor){
//							if (!ActorRole.m_guaji) {
//								role.useCombatSkill(skill);
//								role.initAutoAttack();
//							}
//							else {
//								if (role.canUseCombatSkill(skill, role.m_targetActor)) {
//									role.useCombatSkill(skill);
//									role.initAutoAttack();
//								}
//							}
						}
						else if (skill == null) {// 技能为空
							return MACRO_STATE_EXCEPTION;
						}
						else if (role.m_publicCD_skill_counter > 0) {// 公共CD中
							setAutoAttack(skill);
							return MACRO_STATE_EXCEPTION;
						}
						else if (m_auto_pathfinding) {
							return MACRO_STATE_READY;
						}
						return MACRO_STATE_GOING;
					}
					else if (status == MACRO_STATE_GOING) {
						if (role.m_curCombatSkill == null && !role.m_isCasting && role.m_actionOver
								&& role.m_publicCD_skill_counter <= 0) {
							role.setAction(ActorRole.ACTION_STAND * ActorRole.DIRECT_NUM + role.m_direct, false);
							return MACRO_STATE_FINISH;
						}
						setAutoAttack(skill);
						return MACRO_STATE_GOING;
					}
				}
			case ACTION_TYPE_ITEM:
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					ActorItem item = getActorItemByGuid(ActorItem.TYPE_BAG_ROLE, id);
					if (item != null) {
						if (item.m_type == ActorItem.TYPE_GOODS_CONSUME
								&& item.m_type_detail == ActorItem.TYPE_CONSUME_DRUG) {
							GameManager.getInstance().m_game_message.sendActorItemUse(item.m_layer_actorItem,
									item.m_index);
						}
						else if (item.m_type == ActorItem.TYPE_GOODS_OTHER
								&& item.m_type_detail == ActorItem.TYPE_OTHER_RIDE) {
							if ( m_isride ) {
								if ( GameManager.getInstance().m_role.m_issendride == -1 ) {
									GameManager.getInstance().m_role.m_issendride = 1;
									zqIsUseRide(false, null, (byte) -1);
									GameManager.getInstance().m_game_message.sendRideClose();
								}
							}
							else {
								ride((ActorItemRide) item);
							}
						}
					}
				}
				break;
			case ACTION_TYPE_FUNCTION:
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					MenuFunction.doAction(id);
				}
				break;
		}
		return MACRO_STATE_FINISH;
	}

	/**
	 * 设置自动攻击, 先停留10帧
	 */
	public void initAutoAttack()
	{
		if (m_buffer_skill == null) {
			m_buffer_skill = GameManager.getInstance().m_role.getCombatSkill(CombatSkill.ID_DK_PG);
			if (m_buffer_skill != null) {
				m_buffer_time = AUTO_ATTACK_TIME
						+ (m_buffer_skill.m_publicCD > m_buffer_skill.m_cd ? m_buffer_skill.m_publicCD
								: m_buffer_skill.m_cd);
			}
			else {
				Tools.debugPrintln("玩家技能异常,没有普通攻击!");
			}
		}
	}

	/**
	 * 设置下一次技能, 按键缓存
	 * 
	 * @param skill
	 */
	private void setAutoAttack(RoleCombatSkill skill)
	{
		if (m_status != ACTOR_STATUS_ROLE_DEAD)
			m_buffer_skill = skill;
	}

	/**
	 * 清除自动攻击
	 */
	public void clearAutoAttack()
	{
		m_buffer_skill = null;
		m_buffer_time = 0;
	}

	public boolean m_isride = false; // 人物坐骑状态
	public byte m_issendride = -1; // 是否已经发送了上下坐骑请求 （-1没有任何请求）（0请求了上坐骑）（1请求了下坐骑）
	public ActorItemRide m_ride; // 坐骑

	/**
	 * 使用坐骑
	 * 
	 * @param isRide
	 */
	public void zqIsUseRide(boolean isRide, String zqURL, byte ridetype)
	{
		m_isride = isRide;
		if (m_isride) {
			Tools.debugPrintln("骑马 坐骑类型=" + ridetype);
			zqloadingRideAnimation(zqURL);
			setAction((ACTION_RIDESTAND1 + ridetype - 1) * DIRECT_NUM + m_direct, 0, 0, true, true);
			m_velocity = m_ride.m_speed;
			Tools.debugPrintln("zqIsUseRide 速度更变：="+m_velocity);
		}
		else {
			Tools.debugPrintln("下马");
			animsDestroy(m_anims[0], m_refsResHead[0]);// 清理坐骑资源
			m_anims[0] = null;
			m_refsResHead[0] = null;
			setAction(ACTION_STAND * DIRECT_NUM + m_direct, 0, 0, true, false);
			m_velocity = Actor.m_velocity_role;
			// String temp;
			// if (m_ride != null) {
			// temp = "下" + m_ride.m_name + "坐骑成功！";
			// // m_ride = null;
			// }
			// else {
			// temp = "下坐骑成功！";
			// }
			// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,
			// temp);
			// temp = null;
		}

	}

	private void zqloadingRideAnimation(String url)
	{
		Animation anim;
		if (m_refsResHead[0] == null) {// 如果当前已经有依赖资源
			m_refsResHead[0] = new ResHead(ObjectAdapter.RESOURCE_TYPE_ANIM, url, 1);
			anim = (Animation) (ResourceManager.getInstance().loadResource(GameManager.getInstance().m_resource_scene,
					m_refsResHead[0]));
			if (anim != null && anim.m_loadFinished) {
				m_anims[0] = anim;
			}
			else {
				m_anims[0] = null;
			}
		}
		else {
			if (!m_refsResHead[0].m_url.equals(url)) {
				ResHead res = new ResHead(ObjectAdapter.RESOURCE_TYPE_ANIM, url, 1);
				anim = (Animation) (ResourceManager.getInstance().loadResource(
						GameManager.getInstance().m_resource_scene, res));
				if (m_anims[0] != null) {
					animsDestroy(m_anims[0], m_refsResHead[0]);
					m_anims[0] = null;
				}
				m_refsResHead[0] = res;
				if (anim != null && anim.m_loadFinished) {
					m_anims[0] = anim;
				}
				else {
					m_anims[0] = null;
				}
			}
		}
	}

	/**
	 * 是否开始上坐骑
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvRideIsStart(DataInputStream dis) throws IOException
	{
		short state = dis.readShort(); // 0失败1成功
		String msg = dis.readUTF();// 提示信息
		Tools.debugPrintln(state + " : 0失败1成功 : " + msg);
		Tools.debugPrintln(msg);
		if (state == 0) { // 失败打断施法
			zqIsUseRide(false, null, (byte) -1);
			// if (!msg.equals("")) {
			// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
			// msg);
			// }
			// ((GameScene) GameManager.getInstance().m_scene).endRideTime();
			// GameManager.getInstance().m_role.stopCasting();
			// GameManager.getInstance().m_role.stopCastingDescription();
		}
		// else {
		// GameManager.getInstance().m_game_message.sendRideOver();
		// }

		// if (state == 1) {
		// GameManager.getInstance().m_role.startCasting(readBarTeam *
		// GameManager.FRAME_PER_SECOND);
		// GameManager.getInstance().m_role.startCastingDescription("使用坐骑");
		// ((GameScene)
		// GameManager.getInstance().m_scene).startRideTime(readBarTeam *
		// GameManager.FRAME_PER_SECOND);
		// }
		GameManager.getInstance().m_role.m_issendride = -1;
	}

	/**
	 * 完成上马
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvRideOver(DataInputStream dis) throws IOException
	{

		try {
			long rideGuID = dis.readLong();// 坐骑的guid
			Tools.debugPrintln("坐骑ID=" + rideGuID);
			for (int i = 0; i < m_bag_goods.length - 1; i++) {
				if (m_bag_goods[i] != null) {
					if (rideGuID == m_bag_goods[i].m_guid) {
						GameManager.getInstance().m_role.m_ride = (ActorItemRide) m_bag_goods[i];
						break;
					}
				}
			}
			if (GameManager.getInstance().m_role.m_ride != null
					&& GameManager.getInstance().m_role.m_ride.m_url.length() > 1) {
				Tools.debugPrintln("AcrorRole m_ride.m_url=" +
						GameManager.getInstance().m_role.m_ride.m_url);
				zqIsUseRide(true, GameManager.getInstance().m_role.m_ride.m_url,
						GameManager.getInstance().m_role.m_ride.m_rideType);
			}
			else {
				Tools.debugPrintln("坐骑的URL空");
			}
		}
		catch (Exception e) {
			Tools.debugPrintln("服务器单独推送上坐骑失败！");
		}
	
		
	}

	/**
	 * 下马
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvRideClose(DataInputStream dis) throws IOException
	{
		short state = dis.readShort(); // 0失败1成功
		String msg = dis.readUTF();// 提示信息
		Tools.debugPrintln(state + "：0失败1成功");
		Tools.debugPrintln(msg);

		if (state == 1) {
			//zqIsUseRide(false, null, (byte) -1);
		}
		else {
			if (!msg.equals("")) {
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C, msg);
			}
		}
		GameManager.getInstance().m_role.m_issendride = -1;
	}
    
	
	/**
	 * 自动攻击
	 */
	public void autoFight()
	{
		ActorRole role = GameManager.getInstance().m_role;
		if (role.m_status == ACTOR_STATUS_ROLE_COMBAT) {
			if (role.m_buffer_skill != null && m_targetActor != null && !role.checkTargetFriend(m_targetActor)) {
				if (role.m_buffer_time <= 0) {
					if (role.canUseCombatSkill(role.m_buffer_skill, m_targetActor)) {
						role.useCombatSkill(role.m_buffer_skill);
						role.initAutoAttack();
					}
					else {
						// role.clearAutoAttack();
						if (role.m_curCombatSkill != null) {
							int pcd = role.m_publicCD_skill_counter;
							int scd = ((RoleCombatSkill) (role.m_curCombatSkill)).m_cd_counter;
							m_buffer_skill = role.getCombatSkill(CombatSkill.ID_DK_PG);
							m_buffer_time = AUTO_ATTACK_TIME + (pcd > scd ? pcd : scd);
						}
					}
				}
				else {
					role.m_buffer_time--;
				}
			}
		}
	}

	// /////////////////////////////////////////////////////
	// 角色复活指令
	// /////////////////////////////////////////////////////
	private String[] m_dead_popups = null;//
	private int[] m_dead_instruct = null;

	/**
	 * 死亡后弹出窗口
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvDeadPopups(DataInputStream dis) throws IOException
	{
		m_dead_ok = false;
		int size = dis.readInt();
		m_dead_popups = null;
		m_dead_popups = new String[size];
		m_dead_instruct = new int[size];
		for (int i = 0; i < size; i++) {
			m_dead_popups[i] = dis.readUTF();
			m_dead_instruct[i] = dis.readInt();
			Tools.debugPrintln("m_dead_popups[" + i + "] = " + m_dead_popups[i]);
			Tools.debugPrintln("m_dead_instruct[" + i + "] = " + m_dead_instruct[i]);
		}
		if (size > 0) {
			showDead();
			m_dead_ok = true;
		}
	}

	public boolean m_dead_ok = false;

	/**
	 * 显示一个死亡后的弹出窗口
	 */
	public void showDeadDialogMenu()
	{
		if (m_status == ACTOR_STATUS_ROLE_DEAD && m_dead_ok && m_dead_popups != null && m_dead_popups.length > 0) {
			if (AbstractGameScreen.anyKeyPressed()) {
				UIManager.getInstance().removeOtherWindows();
				dm = null;
				dm = (UIDialogMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU);
				dm.setContents("请选择", "你已经死亡", m_dead_popups);
				dm.addListener(new UIListener() {
					public void actionPerformed()
					{
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
							if (m_dead_instruct[dm.getCurrentIndex()] > 0) {
								GameManager.getInstance().m_game_message.sendReviveFunction(m_dead_instruct[dm
										.getCurrentIndex()]);
							}
							else {
								UIManager.getInstance().removeWindow(dm);
								dm = null;
							}
						}
						else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
							UIManager.getInstance().removeWindow(dm);
							dm = null;
						}
					}
				});
			}
		}
	}

	public void showDead()
	{
		UIManager.getInstance().removeOtherWindows();
		dm = null;
		dm = (UIDialogMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU);
		dm.setContents("请选择", "你已经死亡", m_dead_popups);
		dm.addListener(new UIListener() {
			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					if (m_dead_instruct[dm.getCurrentIndex()] > 0) {
						GameManager.getInstance().m_game_message.sendReviveFunction(m_dead_instruct[dm
								.getCurrentIndex()]);
					}
					else {
						UIManager.getInstance().removeWindow(dm);
						dm = null;
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(dm);
					dm = null;
				}
			}
		});
	}

	public UIDialogMenu dm = null;
	public UIMessageBox mb = null;

	/**
	 * 他人复活确认
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvReviveConfirmation(DataInputStream dis) throws IOException
	{
		String msg = dis.readUTF();
		if (msg != null) {
			mb = (UIMessageBox) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MESSAGEBOX);
			mb.setCentre();
			mb.setMessage(msg);
			mb.addListener(new UIListener() {
				public void actionPerformed()
				{
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
							|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
						GameManager.getInstance().m_game_message.sendReviveAgree();
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						UIManager.getInstance().removeWindow(mb);
					}
				}
			});
		}
	}

	/**
	 * 同意他人复活
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvReviveAgree(DataInputStream dis) throws IOException
	{
		short status = dis.readShort();
		String msg = dis.readUTF();
		if (status == 1) {
			GameManager.getInstance().m_role.m_hp = dis.readInt();
			if (mb != null) {
				UIManager.getInstance().removeWindow(mb);
				mb = null;
			}
			if (dm != null) {
				UIManager.getInstance().removeWindow(dm);
				dm = null;
				// GameManager.s_isControlledByUi = false;
			}
		}
		else {
			Tools.debugPrintln("同意他人复活失败!" + msg);
		}
	}

	/**
	 * 原地复活
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvRevivePos(DataInputStream dis) throws IOException
	{
		short status = dis.readShort();
		String msg = dis.readUTF();
		if (status == 1) {
			GameManager.getInstance().m_role.m_hp = dis.readInt();
			if (dm != null) {
				UIManager.getInstance().removeWindow(dm);
				dm = null;
				// GameManager.s_isControlledByUi = false;
			}
		}
		else {
			Tools.debugPrintln("原地复活失败!" + msg);
		}
	}

	/**
	 * 更新角色职业
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvUpdateJob(DataInputStream dis) throws IOException
	{
		byte job = dis.readByte();
		Tools.debugPrintln("更新玩家职业 : " + job);
		m_vocation = Tools.resizeArray(m_vocation, m_vocation.length, 1);
		m_vocation[m_vocation.length - 1] = job;
	}

	/**
	 * 更新剑客最大剑气
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvUpdateMaxJQ(DataInputStream dis) throws IOException
	{
		byte maxJQ = dis.readByte();
		Tools.debugPrintln("更新剑客最大剑气" + maxJQ);
		m_mpMax = maxJQ;
	}

	/**
	 * 更新阵营
	 * 
	 * @param dis
	 */
	public void recvUpdateFaction(DataInputStream dis) throws IOException
	{
		m_faction = dis.readByte();
		Tools.debugPrintln("更新阵营 : " + m_faction);
	}

	/**
	 * 读取战场分数
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvBattlefieldScore(DataInputStream dis) throws IOException
	{
		m_bScore_show = false;
		m_faction_key = null;
		m_faction_score = null;
		byte factionSize = dis.readByte();
		m_faction_key = new byte[factionSize];
		m_faction_score = new int[factionSize];
		for (byte i = 0; i < factionSize; i++) {
			m_faction_key[i] = dis.readByte();
			m_faction_score[i] = dis.readInt();
		}
		m_battlefield_score = dis.readInt();
		m_bScore_show = true;
	}

	public void closeBattlefieldScore()
	{
		m_bScore_show = false;
		m_faction_key = null;
		m_faction_score = null;
		m_battlefield_score = 0;
	}

	/**
	 * 绘制战场分数
	 * 
	 * @param g
	 */
	public void drawBattlefieldScore(Graphics g)
	{
		if (m_bScore_show && m_faction_key != null && m_faction_score != null) {
			g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
			for (byte i = 0; i < m_faction_key.length; i++) {
				Tools.drawString(g, FACTION_WORD[m_faction_key[i]] + "  " + m_faction_score[i], Tools.BLACK,
						Tools.YELLOW, AbstractGameScreen.s_font,
						AbstractGameScreen.SCREEN_WIDTH - 2, (AbstractGameScreen.SCREEN_HEIGHT >> 1) + i
								* UITools.H_SINGLE_BAR
								- (m_faction_key.length * UITools.H_SINGLE_BAR >> 1) + 41, Tools.RIGHT_TOP);
			}
			Tools.drawString(g, "杀  " + m_battlefield_score, Tools.BLACK, Tools.RED, AbstractGameScreen.s_font,
					AbstractGameScreen.SCREEN_WIDTH - 2,
					(AbstractGameScreen.SCREEN_HEIGHT >> 1) + (m_faction_key.length * UITools.H_SINGLE_BAR >> 1)
							+ UITools.H_SINGLE_BAR + 41, Tools.RIGHT_TOP);
		}
	}

	public void sceneAutoPathfinding()
	{
		try {
			if (m_pathfinding_start && !m_pathfinding_pause) {
				if (m_pathfinding_point == null || m_pathfinding_label >= m_pathfinding_point.size()) {// 已经到达最后点
					clearPathfinding();
				}
				else {
					Background background = GameManager.getInstance().m_scene.m_bg;
					int info = ((Integer) (m_pathfinding_point.elementAt(m_pathfinding_label))).intValue();
					int x = info & 0x0000ffff;
					int y = (info >> 16) & 0x0000ffff;
					if (m_pathfinding_paths == null) {// 路径为空
						int start = BinHeapAStar.convertXYtoPoint(GameManager.getInstance().m_role.m_posX, GameManager
								.getInstance().m_role.m_posY, background.m_tileW,
								background.m_tileH, background.m_columns);
						int end = BinHeapAStar.convertXYtoPoint(x, y, background.m_tileW, background.m_tileH,
								background.m_columns);
						m_pathfinding_paths = BinHeapAStar.findPath(background.getPhyData(), background.m_columns,
								background.m_rows, start, end);
						Tools.debugPrintln("第" + m_pathfinding_label + "次寻路 : " + x + " : " + y);
						if (m_pathfinding_paths == null) {
							Tools.debugPrintln("无法到达当前点!" + background.m_resHead.m_url);
							clearPathfinding();
						}
					}
					else {
						if (Tools.abs(GameManager.getInstance().m_role.m_posX - x) < (background.m_tileW << 1)
								&& Tools.abs(GameManager.getInstance().m_role.m_posY - y) < (background.m_tileH << 1)) {
							if (m_pathfinding_label == m_pathfinding_point.size() - 1) {// 到达最后的点
								ActorNPC npc = ((GameScene) m_scene).getNPCByID(m_pathfinding_id);
								Tools.debugPrintln("任务寻路结束 搜索ID : " + m_pathfinding_id);
								if (npc != null) {
									if (npc.m_type == ActorNPC.ACTOR_TYPE_NPC
											|| npc.m_type == ActorNPC.ACTOR_TYPE_GATHERING) {
										((GameScene) m_scene).setTargetActor(npc);
										GameManager.getInstance().m_game_message.sendNPCList(npc.m_gameID);
									}
									else if (npc.m_type == ActorNPC.ACTOR_TYPE_GATE) {
										npc.findPathGate();
									}
									else if (npc.m_type == ActorNPC.ACTOR_TYPE_MONSTER) {
										((GameScene) m_scene).setTargetActor(npc);
									}
								}
								((GameScene) m_scene).m_controlledActor.stay(GameManager.getInstance().m_role.m_direct);
								clearPathfinding();
							}
							else {// 没到达最后的点,需要等玩家点击传送
								pausePathfinding();
								findGateway();
							}
						}
						else {
							if (m_pathfinding_index >= m_pathfinding_paths.length) {
								Tools.debugPrintln("自动走路中越界 : " + m_pathfinding_paths.length + " : "
										+ m_pathfinding_index);
								Tools.debugPrintln("当前点 : " + GameManager.getInstance().m_role.m_posX + " : "
										+ GameManager.getInstance().m_role.m_posY);
								Tools.debugPrintln("目标点 : " + x + " : " + y);
								clearPathfinding();
							}
							else {
								int targetX = ((m_pathfinding_paths[m_pathfinding_index] % background.m_columns) * background.m_tileW)
										+ (background.m_tileW >> 1);
								int targetY = ((m_pathfinding_paths[m_pathfinding_index] / background.m_columns) * background.m_tileH)
										+ (background.m_tileH >> 1);
								int dValueX = GameManager.getInstance().m_role.m_posX - targetX;
								int dValueY = GameManager.getInstance().m_role.m_posY - targetY;
								int speed = GameManager.getInstance().m_role.m_velocity >> Actor.ACTOR_FRACTION_BIT;
								if (Tools.abs(dValueX) > speed) {
									if (dValueX > 0) {
										GameManager.getInstance().m_role.move(ActorRole.DIRECT_W);
									}
									else {
										GameManager.getInstance().m_role.move(ActorRole.DIRECT_E);
									}
								}
								else if (Tools.abs(dValueY) > speed) {
									if (dValueY > 0) {
										GameManager.getInstance().m_role.move(ActorRole.DIRECT_N);
									}
									else {
										GameManager.getInstance().m_role.move(ActorRole.DIRECT_S);
									}
								}
								else {
									m_pathfinding_index++;
								}
							}
						}
					}
				}
			}
		}
		catch (Exception e) {
			Tools.debugPrintln("寻路异常" + e.toString());
			clearPathfinding();
		}
	}

	/**
	 * 跟随目标
	 */
	public void scenefollowTarget()
	{
		if (m_followTarget) {
//			GameManager gm = GameManager.getInstance();
			Background background = GameManager.getInstance().m_scene.m_bg;
			if (m_followTarget_point.size() != 0) {
				int info = ((Integer) (m_followTarget_point.elementAt(0))).intValue();
				int x = info & 0x0000ffff;
				int y = (info >> 16) & 0x0000ffff;

				int start = BinHeapAStar.convertXYtoPoint(GameManager.getInstance().m_role.m_posX, GameManager
						.getInstance().m_role.m_posY, background.m_tileW, background.m_tileH,
						background.m_columns);
				int end = BinHeapAStar.convertXYtoPoint(x, y, background.m_tileW, background.m_tileH,
						background.m_columns);
				m_followTarget_paths = BinHeapAStar.findPath(background.getPhyData(), background.m_columns,
						background.m_rows, start, end);
				if (m_followTarget_paths == null) {
					Tools.debugPrintln("无法到达当前点!" + background.m_resHead.m_url);
				}
				else {
					m_followTarget_index = 0;
				}
				m_followTarget_point.removeElementAt(0);
				m_follow_isArriveTarget = true;
			}
			if (m_followTarget_paths != null) {// 路径为空
				// 自动走路中
				if (m_followTarget_index >= m_followTarget_paths.length) {
					// Tools.debugPrintln("自动走路中越界 : " +
					// gm.m_followTarget_paths.length + " : "
					// + gm.m_followTarget_index);
					m_followTarget_index = 0;
					m_followTarget_paths = null;
					m_follow_isArriveTarget = false;
				}
				else {
					int targetX = ((m_followTarget_paths[m_followTarget_index] % background.m_columns) * background.m_tileW)
							+ (background.m_tileW >> 1);
					int targetY = ((m_followTarget_paths[m_followTarget_index] / background.m_columns) * background.m_tileH)
							+ (background.m_tileH >> 1);
					int dValueX = GameManager.getInstance().m_role.m_posX - targetX;
					int dValueY = GameManager.getInstance().m_role.m_posY - targetY;
					int speed = GameManager.getInstance().m_role.m_velocity >> Actor.ACTOR_FRACTION_BIT;
					if (Tools.abs(dValueX) > speed) {
						if (dValueX > 0) {
							GameManager.getInstance().m_role.move(ActorRole.DIRECT_W);
						}
						else {
							GameManager.getInstance().m_role.move(ActorRole.DIRECT_E);
						}
					}
					else if (Tools.abs(dValueY) > speed) {
						if (dValueY > 0) {
							GameManager.getInstance().m_role.move(ActorRole.DIRECT_N);
						}
						else {
							GameManager.getInstance().m_role.move(ActorRole.DIRECT_S);
						}
					}
					else {

						m_followTarget_index++;
					}
				}
			}
		}
	}

	private void followTargetUpdataPoint()
	{
		if (m_followTarget) {
			ActorRole role = ((GameScene) GameManager.getInstance().m_scene).getRoleByID(m_followTarget_id);
			if (role == null) {
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "跟随目标丢失");
				GameManager.getInstance().m_role.clearPathfinding();
				m_followTarget = false;
				GameManager.getInstance().m_role.stay(GameManager.getInstance().m_role.m_direct);
				return;
			}
			if (role != null) {
				// Tools.debugPrintln("role.m_flexBuffer.size()  "+role.m_flexBuffer.size());
				// short[] point = ((short[]) role.m_flexBuffer.elementAt(0));
				short x = (short) role.m_posX;
				short y = (short) role.m_posY;
				m_followTarget_point.addElement(new Integer(x | (y << 16)));
			}
		}
	}

	public void followTargetStart(long id)
	{
		if (isAliveStatus()) {
			clearFollowTarget();
			m_followTarget_point = new ArrayList();
			m_followTarget_id = id;
			m_followTarget = true;
			clearPathfinding();
		}
	}

	/**
	 * 寻找传送门
	 */
	public void findGateway()
	{
		Vector actors = GameManager.getInstance().m_scene.m_dynamic_actors;
		for (int i = 0; i < actors.size(); i++) {
			final Actor actor = (Actor) actors.elementAt(i);
			if (actor != null && actor instanceof ActorNPC) {
				if (((ActorNPC) actor).m_type == AbstractGameActor.ACTOR_TYPE_GATE
						&& actor.activeCollide(((GameScene) m_scene).m_controlledActor, true)) {
					// 弹出切换框
					// final UIMessageBox messageBox = (UIMessageBox)
					// UIManager.getInstance().createWindow(
					// UIWindowFactory.WINDOW_MESSAGEBOX);
					// messageBox.setMessage("确认去" + ((ActorNPC) actor).m_name +
					// "?");
					// messageBox.addListener(new UIListener() {
					// public void actionPerformed() {
					// if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
					//	 || AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A))
					// {
					// GameManager.getInstance().m_game_message.sendChange(((ActorNPC)
					// actor).m_gameID);
					// UIManager.getInstance().removeWindow(messageBox);
					// }
					// else if
					// (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT))
					// {
					// UIManager.getInstance().removeWindow(messageBox);
					// }
					// }
					// });
					GameManager.getInstance().m_is_autopath = true;
					GameManager.getInstance().m_game_message.sendChange(((ActorNPC) actor).m_gameID);
					// 设置角色站立
					((GameScene) m_scene).m_controlledActor.stay(GameManager.getInstance().m_role.m_direct);
				}
			}
		}
	}

	/**
	 * 清理寻路数据
	 */
	public void clearPathfinding()
	{
		m_pathfinding_point = null;// 寻路终点集合
		m_pathfinding_label = 0;// 寻路终点索引
		m_pathfinding_pause = false;// 是否暂停
		m_pathfinding_start = false;// 是否在寻路
		m_pathfinding_paths = null;// 寻路的路径集合
		m_pathfinding_index = 0;
		m_pathfinding_id = 0;// 寻路的目标ID
	}

	public void pausePathfinding()
	{
		m_pathfinding_label++;
		m_pathfinding_index = 0;
		m_pathfinding_paths = null;
		m_pathfinding_pause = true;
		stay(m_direct);
	}

	/**
	 * 清除跟随
	 */
	public void clearFollowTarget()
	{
		m_followTarget_point = null;// 跟随终点集合
		m_followTarget = false; // 是否开始跟随
		m_followTarget_paths = null;// 跟随的路径集合
		m_followTarget_index = 0;
		m_followTarget_id = 0;// 跟随的目标ID
		m_follow_isArriveTarget = false;
	}

	// // 角色行为
	// ////////////////////////////////////////////////////////////

	// ////////////////////////////////////////////////////////////
	// // 坐骑
	// public Animation m_anim_ride;

	// // 坐骑
	// ////////////////////////////////////////////////////////////

	public synchronized void updateComponent(ResHead head, Serializeable component)
	{
		if (m_loadFinished)
			return;
		if (head.m_type != ObjectAdapter.RESOURCE_TYPE_ANIM)
			return;
		if (m_refsResHead == null || m_refsResHead.length == 0)
			return;
		for (int i = 0; i < m_refsResHead.length; i++) {
			if (m_refsResHead[i] != null && m_refsResHead[i].equals(head)) {
				if (m_anims[i] != GameManager.getInstance().m_shadowAnimation)
					m_anims[i] = (Animation) component;
				checkLoadFinished();
			}
		}
		m_anim = m_anims[1];
	}

	/**
	 * 一键上下坐骑,供背包外部调用
	 */
	public void ride()
	{
		if (m_ride == null) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "您需要在背包中使用一次坐骑，才能激活一键坐骑。");
			return;
		}
		ride(m_ride);
	}

	/**
	 * 一键上下坐骑 2012-4-24 上午11:09:08 venizeng
	 * 
	 * @param id
	 */
	public void ride(ActorItemRide item)
	{
//		if (GameManager.getInstance().m_role.m_pathfinding_start) {
//			GameManager.getInstance().m_role.stay(GameManager.getInstance().m_role.m_direct);
//			GameManager.getInstance().m_role.clearPathfinding();
//			GameManager.getInstance().m_role.m_pathfinding_pause = true;
//		}
//		if (GameManager.getInstance().m_role.m_followTarget) {
//			GameManager.getInstance().m_role.stay(GameManager.getInstance().m_role.m_direct);
//			GameManager.getInstance().m_role.clearFollowTarget();
//		}
		if (GameManager.getInstance().m_role.m_status == AbstractGameActor.ACTOR_STATUS_ROLE_COMBAT) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "战斗状态不能使用坐骑！");
		}
		else if (GameManager.getInstance().m_role.m_status == AbstractGameActor.ACTOR_STATUS_ROLE_FREE) {
			if (GameManager.getInstance().m_role.m_issendride == -1) {// 是否已经发送过上坐骑
																// true 没上
				GameManager.getInstance().m_role.m_issendride = 0;
				m_ride = item;
				// int readTime = 5;// 读条时间
				// GameManager.getInstance().m_role.sendOnecMove();
				
				// GameManager.getInstance().m_role.startCasting(readTime *
				// GameManager.FRAME_PER_SECOND);
				// GameManager.getInstance().m_role.startCastingDescription("召唤坐骑");
				// ((GameScene)
				// GameManager.getInstance().m_scene).startRideTime(readTime *
				// GameManager.FRAME_PER_SECOND);
				long rideGuID = item.m_guid;
				Tools.debugPrintln("坐骑ID=" + rideGuID);
				if (item != null && item.m_url.length() > 1) {
					Tools.debugPrintln("AcrorRole m_ride.m_url=" + item.m_url);
					GameManager.getInstance().m_role.zqIsUseRide(true, item.m_url, item.m_rideType);
				}
				else {
					Tools.debugPrintln("坐骑的URL空");
				}
				GameManager.getInstance().m_game_message.sendRideStart(item.m_guid);
				UIBag uiBag = (UIBag) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_BAG);
				if (uiBag != null) {
					UIManager.getInstance().removeWindow(uiBag);
				}
				UIMenu uiMenu = (UIMenu) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MENU_LR);
				if (uiMenu != null) {
					UIManager.getInstance().removeWindow(uiMenu);
				}
			}
		}
	}

	/**
	 * 动作列表
	 */
	public static final int ACTION_STAND = 0;
	public static final int ACTION_MOVE = 1;
	public static final int ACTION_SIT = 2;
	public static final int ACTION_LIE = 3;
	public static final int ACTION_FLY = 4;
	public static final int ACTION_SITDOWN = 5;
	public static final int ACTION_STANDUP = 6;
	public static final int ACTION_JUMP = 7;
	public static final int ACTION_FALL = 8;
	public static final int ACTION_PICK = 9;
	public static final int ACTION_MAKE = 10;
	public static final int ACTION_EAT = 11;
	public static final int ACTION_ACCLAIM = 12;
	public static final int ACTION_OTHER1 = 13;
	public static final int ACTION_OTHER2 = 14;
	public static final int ACTION_OTHER3 = 15;
	public static final int ACTION_HURT1 = 16;
	public static final int ACTION_HURT2 = 17;
	public static final int ACTION_HURT3 = 18;
	public static final int ACTION_HURT4 = 19;
	public static final int ACTION_HURT5 = 20;
	public static final int ACTION_HURT6 = 21;
	public static final int ACTION_DEAD1 = 22;
	public static final int ACTION_DEAD2 = 23;
	public static final int ACTION_DEAD3 = 24;
	public static final int ACTION_DEAD4 = 25;

	public static final int ACTION_ATTACK1 = 26;
	public static final int ACTION_ATTACK2 = 27;
	public static final int ACTION_ATTACK3 = 28;
	public static final int ACTION_ATTACK4 = 29;
	public static final int ACTION_ATTACK5 = 30;
	public static final int ACTION_ATTACK6 = 31;
	public static final int ACTION_ATTACK7 = 32;
	public static final int ACTION_ATTACK8 = 33;
	public static final int ACTION_CAST1 = 34;
	public static final int ACTION_CAST2 = 35;
	public static final int ACTION_CAST3 = 36;
	public static final int ACTION_CAST4 = 37;
	public static final int ACTION_CAST5 = 38;
	public static final int ACTION_CAST6 = 39;
	// 坐骑动作
	public static final int ACTION_RIDESTAND1 = 40; // 站在坐骑上
	public static final int ACTION_RIDESTAND2 = 41; // 跨在坐骑上
	public static final int ACTION_RIDESTAND3 = 42; // 坐在坐骑上

	public static final int ACTION_RIDEMOVE1 = 43;
	public static final int ACTION_RIDEMOVE2 = 44;
	public static final int ACTION_RIDEMOVE3 = 45;
	// ///////// ///////////////////////////////////////////////////////////
	public static final int ACTION_HEAD = 184; // 头像
    //zuobi 挂机
	public static boolean m_guaji = false;
	public static int s_time;
	
	public void guaji(){
		if( m_status == ACTOR_STATUS_ROLE_DEAD){
			m_guaji = false;
			return;
		}
		if( m_guaji ){
			Tools.debugPrintln("进挂机！");
			boolean flag = s_time > 0?false:true;
			if( s_time > 0 ){
				s_time--;
			}
			if(m_hp <= (m_hpMax/5*4) && flag){
				Tools.debugPrintln("挂机回血");
				GameManager.getInstance().m_game_message.sendAutoEat((byte)1);
				s_time = 40;
//				GameManager.getInstance().m_role.stopMacro();
//				doAction(m_shortcut[m_shortcut_bar][4]);
			}
			boolean isMp = true;
			if( m_vocation[0] == ActorRole.VOCATION_DAO_SHI && m_mp <= (m_mpMax >>1) ){
				if(flag){
					Tools.debugPrintln("挂机回蓝");
					GameManager.getInstance().m_game_message.sendAutoEat((byte)2);
					s_time = 40;
				}
				isMp = false;
//				GameManager.getInstance().m_role.stopMacro();
//				doAction(m_shortcut[m_shortcut_bar][5]);
			}		
			if( m_targetActor == null ){
				((GameScene) m_scene).changeTargetActor(false, false);
			}else{
				if (m_targetActor.m_type != AbstractGameActor.ACTOR_TYPE_MONSTER) {
					((GameScene) m_scene).changeTargetActor(false, false);
				}
				else {
					short skillgroupId;
					switch(m_vocation[0]){
						case ActorRole.VOCATION_JIAN_KE:
							skillgroupId = 1001;
							break;
						case ActorRole.VOCATION_WU_ZHE:
							skillgroupId = 1007;
							break;
						case ActorRole.VOCATION_DAO_SHI:
							if(!isMp){//蓝不够
								skillgroupId = CombatSkill.ID_DK_PG;
							}else{
								skillgroupId = 1013;	
							}
							break;
						default:
							skillgroupId = CombatSkill.ID_DK_PG;
							break;
					}
					if (isAliveStatus()) {
						RoleCombatSkill skill = getGroupSkill(skillgroupId);
						if (canUseCombatSkill(skill, m_targetActor)) {// 冷却中,播放中,法力不足
							useCombatSkill(skill);
							initAutoAttack();
						}
//					GameManager.getInstance().m_role.stopMacro();
//					doAction(m_shortcut[m_shortcut_bar][1]);
					}
				}
			}
			if( m_bag_equipment != null && m_bag_equipment.length > 1 && flag){
				int size = m_bag_equipment.length;
				for(int i=0;i<size;i++){
					ActorItem item = m_bag_equipment[i];
					if(item instanceof ActorItemEquip){
						if( item.m_type == ActorItem.TYPE_GOODS_EQUIPMENT){
							switch(item.m_type_detail){
								case ActorItem.TYPE_EQUIPMENT_WEAPON_MAG:
								case ActorItem.TYPE_EQUIPMENT_WEAPON_MUL:
								case ActorItem.TYPE_EQUIPMENT_WEAPON_SIN:
									ActorItemEquip equip = (ActorItemEquip) item;
									if( equip.m_naijiu <= 10){
										Tools.debugPrintln("装备栏武器="+item.m_name+";耐久="+equip.m_naijiu);
										GameManager.getInstance().m_game_message.sendNpcFixAllEquip();
										continue;
									}
									break;
							}	
						}
					}
				}
			}
		}
	}
}
